-1

Please help me. I have a problem!

e.g.

<!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>

Please tell me why it is not work ?! Also if i did:

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

It doesn't work! Any suggestions!

2 Answers2

2

The problem comes from adding the mobile version of jQuery. Try adding this script before including jquery mobile.

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

Here is the complete code:

<!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>
Gabriel Ilharco
  • 1,649
  • 1
  • 21
  • 34
0

So I don't have enough reputation to comment on a post. But a good way to debug in safari is to go into preferences and then in the advanced section of preferences at the very bottom there is a checkbox that says, "Show develop menu in menu bar." Make sure this box is checked.

After that you go to the Develop section of your menu bar and select the option show error console. This will show you the error you are experiencing.

Here is a picture of what the error console looks like and an example of errors. The errors are displayed in red text.

The Error Console in Safari

As to the problem with your code it is in fact that you didn't include a link to a jQuery library. You can do this a few ways. The way that was suggested earlier will only work when you have an internet connection. If you want you can download the jQuery library from their website and save it to your websites folder. Then all you need to do is just link to the file like you would any other external javascript file by using the script tags.

jQuery download page: https://jquery.com/download/

Example:

<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>
James
  • 31
  • 3