在jQuery选择器中使用变量 [英] Use variable in jQuery selector
本文介绍了在jQuery选择器中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的函数中,我希望 idurl
是带有后缀的单词apple。后缀为 number
,其中包含一个数字。示例将是 apple12
。
In the function below, I'd like the idurl
be the word apple with a suffix. The suffix is number
containing a number. Example would be apple12
.
但在下面的函数中,我有麻烦连接变量 number
用单词apple。
But in the function below, I have trouble concatenating the variable number
with the word apple.
function apple(number) {
if (something === "0") {
$('.onchange :checkbox[idurl="apple" + number]').prop('checked', false);
} else {
$('.onchange :checkbox[idurl="apple" + number]').prop('checked', true);
}
};
我尝试使用额外的或[],但它迄今为止还不是很成功。 number
不会被识别为变量,因此不会与单词apple连接。
I tried using extra " or [] but it hasn't been very succesfull so far. The variable number
is not bein recognized as a variable and thus not concatenated with the word apple.
推荐答案
use
$('.onchange :checkbox[idurl="apple"' + number+']').prop('checked', false);
断开字符串:
第一部分'。onchange:checkbox [idurl =apple'
第二部分号
字符串的第三部分']'
。
这篇关于在jQuery选择器中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文