Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.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 为什么(';.class';,this)不起作用?_Jquery_Html_Jquery Mobile - Fatal编程技术网

Jquery 为什么(';.class';,this)不起作用?

Jquery 为什么(';.class';,this)不起作用?,jquery,html,jquery-mobile,Jquery,Html,Jquery Mobile,这两个脚本都不适用于JQuery Mobile JS HTML 是否有任何原因使这些函数不能与下面的文本一起工作?Huangism是正确的,因为如果此不是正确的上下文(将是.class项的父元素),则这是一个根本问题。在这种情况下,您可以尝试将此更改为文档,这有点繁琐,但会告诉您这是否是您的问题 否则,由于要将tap事件附加到的项目是动态添加的,因此您需要将事件附加到其父级,this,并在单击classclass的元素时通知事件激发 $( this ).on( "tap", ".class"

这两个脚本都不适用于JQuery Mobile

JS

HTML



是否有任何原因使这些函数不能与下面的文本一起工作?

Huangism是正确的,因为如果
不是正确的上下文(将是
.class
项的父元素),则这是一个根本问题。在这种情况下,您可以尝试将
更改为
文档
,这有点繁琐,但会告诉您这是否是您的问题

否则,由于要将tap事件附加到的项目是动态添加的,因此您需要将事件附加到其父级,
this
,并在单击class
class
的元素时通知事件激发

$( this ).on( "tap", ".class", function() {
  $( ".class-hidden" ).toggle( "slow" );
});

什么是
这个
?不,这只是在制作示例时的一个输入错误。我正在搜索jquery mobile中的一个bug,它可以解释为什么这不起作用。我坚信这与jquery mobile有关,因为事件可以通过非jquery mobile操作记录。页面加载时,.class元素存在还是动态添加?我认为最重要的问题是中的第一个问题comments@JaredFarrish
$()的上下文参数
与使用
find()
not
filter()
<div class="class">
    <div class="class-hidden">
    </div>
</div>
$( this ).on( "tap", ".class", function() {
  $( ".class-hidden" ).toggle( "slow" );
});