jQuery:将变量传递给:eq()不起作用 [英] jQuery: Pass variable to :eq() does not work
本文介绍了jQuery:将变量传递给:eq()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直试图找出以下代码行不起作用的原因:
I have been trying to find out why the following lines of code do not work:
$('#add-cloud > select').change(function() {
var selected = parseInt($('#add-cloud select option:selected').val());
$("#cloud-calculator table tr:eq(selected)").css("color", "red");
});
如果我更改:eq(已选择)
到:例如eq(4)
- 工作正常。如何将变量作为参数传递给:eq()
?
If I change :eq(selected)
to :eq(4)
for example - works fine. How do you pass variable as an argument to :eq()
?
推荐答案
您必须将变量与选择器连接:
You have to concatenate your variable with your selector:
$("tr:eq("+selected+")");
这篇关于jQuery:将变量传递给:eq()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文