jQuery ID & function

jQuery ID & function

本文关键字:function amp ID jQuery      更新时间:2023-09-26

请帮帮我。我有问题!

例如

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <body>
        <input type="button" id="clickmenow" value="ADD" />
        <script type="text/javascript">
      $('#clickmenow').click(function() {
    window.alert("DO IT");
});          
      </script>      
    </body>
</html>

请告诉我为什么它不起作用?!如果我这样做了:

<script type="text/javascript">
        $(document).ready(function(){
            $("clickmenow").click(function(){
                window.alert("SHOWTHAT");
            });
        });
        </script>

它不起作用!有什么建议吗!

问题来自于添加jQuery的移动版本。请尝试在包含jquery mobile之前添加此脚本。

<script>
    $(document).bind('mobileinit',function(){
        $.mobile.changePage.defaults.changeHash = false;
        $.mobile.hashListeningEnabled = false;
        $.mobile.pushStateEnabled = false;
    });
</script>

这是完整的代码:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
    $(document).bind('mobileinit',function(){
        $.mobile.changePage.defaults.changeHash = false;
        $.mobile.hashListeningEnabled = false;
        $.mobile.pushStateEnabled = false;
    });
</script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <body>
        <input type="button" id="clickmenow" value="ADD" />
        <script type="text/javascript">
            $('#clickmenow').click(function() {
                window.alert("DO IT");
            });          
      </script>      
    </body>
</html>

所以我没有足够的声誉来评论一篇帖子。但在safari中调试的一个好方法是进入首选项,然后在最底部的首选项高级部分有一个复选框,上面写着"在菜单栏中显示开发菜单"。请确保选中此复选框。

之后,转到菜单栏的"开发"部分,选择"显示错误控制台"选项。这将显示您遇到的错误。

下面是一张错误控制台的图片和一个错误示例。错误显示为红色文本。

Safari 中的错误控制台

至于代码的问题,实际上您没有包含指向jQuery库的链接。你可以用几种方法做到这一点。前面建议的方法只有在你有互联网连接的情况下才能奏效。如果你愿意,你可以从他们的网站下载jQuery库,并将其保存到你的网站文件夹中。然后,您所需要做的就是使用script标记链接到该文件,就像链接到任何其他外部javascript文件一样。

jQuery下载页面:https://jquery.com/download/

示例:

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../jquery-ui-1.11.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="../js/blur.js"></script>