无法在jquerymobile中使用单击操作

时间:2011-03-28 12:03:20

标签: jquery-mobile

我尝试在

  • 项目上添加点击功能,但似乎无效。

     $(document).ready(function(){
     $("#vibrateBtn").click(function() {
     window.alert('test');
     });
     });
    

    我尝试使用>

    禁用Ajax加载
    $(document).bind("mobileinit", function(){
     ajaxEnabled:false;
    });
    

    但结果相同。

    请问哪里有问题?

    感谢您的任何建议。

  • 2 个答案:

    答案 0 :(得分:2)

    在jquery mobile document.ready()中不起作用并使用.live绑定click事件而不是使用short hard .click()。 还有pagebeforecreate,pagecreate等其他事件。检查jquery demo以查看活动列表。

    $(document).live('pageshow',function(){
    
       $("#vibrateBtn").live('click',function() {
            window.alert('test');
       });
    
    });
    

    答案 1 :(得分:0)

    请尝试此代码

    <html>
    <head>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
    
    <script language="javascript">
    
        $(function() {
         $('#theButton').on('tap click',function(event, ui) {
            alert('The Button has been clicked');
         });
        });
    
    </script>
    </head>
    <body>
    <div data-role="page">
    <div data-role="content">
        <input type="button" id="theButton" name="theButton" value="The Button">
    </div>
    </div>
    </body>
    </html>