[英]Selecting by data- attribute with jQuery - works in chrome, not firefox. Alternative?
This is a sample element: 这是一个示例元素:
<textarea type="text" data-class-changer="question" class="questioninputcss" data-integer-question="877"></textarea>
This jQuery script works in Chrome, but not in firefox: 此jQuery脚本可在Chrome中使用,但不能在Firefox中使用:
$("#reset").click(function(){
$("[data-integer-question").attr("class", "questioninputcss");
});
I also tried it with an asterisk, like this: $("*[data-integer-question")
, but that doesn't work either. 我也用一个星号尝试过,例如:
$("*[data-integer-question")
,但这也不起作用。
Chrome does not produce an error, and it works correctly. Chrome不会产生错误,并且可以正常工作。
Firefox does not work, and produces this error: Firefox无法正常工作,并产生以下错误:
Error: Syntax error, unrecognized expression: [data-integer-question
How can I work around this? 我该如何解决? Thanks.
谢谢。
You have a simple typo in your code. 您的代码中有一个简单的错字。 The code should read:
该代码应显示为:
$("#reset").click(function(){
$("textarea[data-integer-question]").attr("class", "questioninputcss");
});
You omitted the trailing square bracket ]
. 您省略了方括号
]
。
There is a missing ']'
as shown : 缺少一个
']'
,如下所示:
$("#reset").click(function(){
$("[data-integer-question]").attr("class", "questioninputcss");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.