在jquery mobile中使用自定义jquery?

在jquery mobile中使用自定义jquery?,jquery,jquery-mobile,Jquery,Jquery Mobile,我在jquery移动站点中使用了一些自定义jquery事件。我在jquery mobile include之前加入了这个custom.js,因为我相信这是正确的做法。jquery首先被包括在内。这些文件包含在每一页中 <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script> <script src="/components/m/js/custom.js"></script>

我在jquery移动站点中使用了一些自定义jquery事件。我在jquery mobile include之前加入了这个custom.js,因为我相信这是正确的做法。jquery首先被包括在内。这些文件包含在每一页中

<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="/components/m/js/custom.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>

当我加载主索引页时,没有使用custom.js的元素。当我点击一个页面进入更深一层时,我的问题就出现了。因此,我单击一个链接来查看custom.js中有一个事件的艺术家,当jquery mobile执行该操作时,我的单击事件不起作用

但是,如果我重新加载页面,自定义单击事件将正常工作


我错过了什么?我是否应该使用.live('click'而不是.click?

在与Gajotres交谈后(通过上述评论中的电子邮件),我们得出以下结论

我的自定义js文件实际上必须位于jQM文件之后

<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 src="/components/m/js/custom-alt.js"></script>
以前,我使用的是“mobileint”而不是“pageint”,正如Gajotres所引用的:

原因是,pageinit事件仅在加载jQuery Mobile js文件时有效。我还看到您甚至尝试使用mobileinit 该事件应该在jQuery Mobile js文件之前使用(到目前为止还不错),但您可以使用它绑定并单击事件,因为 需要加载jQM js文件来初始化页面元素


你是否已经尝试过使用live('click')?在我看来,这是最容易找到答案的方法。我注意到live('click')在触发时会有一些效果,但我的ajax调用不会起作用。但是如果我刷新页面,它会很好地工作。那么,小步骤。那个更深的页面,可能是一个多页面吗(包含多个带有
data role=“page”
div
标记)jQM文件?还显示定义单击处理程序的相关代码,包括放置它们的外部页面范围的处理程序。Mike,如果你想将自定义js文件发送到我的邮件,我会告诉你问题出在哪里。我想我已经知道,要绑定到页面元素或页面的每个事件(页面事件除外)必须绑定到正确的jQM页面事件中。
$(document).bind("pageinit", function() {
    var btnAddComment = $('#btn-addcomment');

    // register functions with jqm framework
    $(btnAddComment).bind('touchstart mousedown', function(e){
        e.preventDefault();
        clickCommentAdd(); 
    }); 

    function clickCommentAdd() {
        $("#form-comment").toggle();
        return false;
    }
});