Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用;这";单击事件处理程序中的对象_Jquery_Cordova_Phonegap Build - Fatal编程技术网

Jquery 使用;这";单击事件处理程序中的对象

Jquery 使用;这";单击事件处理程序中的对象,jquery,cordova,phonegap-build,Jquery,Cordova,Phonegap Build,我正在写PhoneGap应用程序。我使用PhoneGap构建web服务编译它。我没有包括jQuery Mobile,尽管我在项目中包括了jQuery。在纯web应用程序中,我经常使用以下代码: <html> <body> <div class="button" id="button1">Hello</div> <script> $(".button").click(fun

我正在写PhoneGap应用程序。我使用PhoneGap构建web服务编译它。我没有包括jQuery Mobile,尽管我在项目中包括了jQuery。在纯web应用程序中,我经常使用以下代码:

<html>
    <body>
        <div class="button" id="button1">Hello</div>
        <script> 
            $(".button").click(function() {
                alert($(this).attr("id"));
            });
        </script>
    </body>
</html>

你好
$(“.button”)。单击(函数(){
警报($(this.attr(“id”));
});

然而,在PhoneGap中,我发现当我通过jQuery的
$(“.button”)
元素的
$(this)
引用任何属性时,该属性的值是
未定义的。我该怎么办?

事件未触发,因为文档未准备好。对于phonegap,我需要在deviceReady()方法中注册事件。这里有更多关于该活动的信息:

如果我使用$(this)引用任何内容,则该值未定义。示例:警报($(this.attr(“id”));或警报($(this.html());是的,包括Jquery。我能够在整个页面中广泛地使用JQuery的may功能,只是“$(this)”失败了。您是否使用了
jQuery(this)
?@kmsdev如果
$(“.button”)
有效,那么
$(this)
应该不会有任何问题。我知道,这就是我写“奇怪”的原因。这段代码应该按预期工作(如果jQuery已经加载)