嘿。我想将变量作为参数传递给第n个子选择器 这不起作用:
var position = 5;
$("#daddy > div:nth-child(position)").animate({
opacity: 0.01,
}, 500);
虽然可以吗? 干杯,杰克
答案 0 :(得分:34)
尝试:
var position = 5;
$("#daddy > div:nth-child(" + position + ")").animate({
opacity: 0.01,
}, 500);
答案 1 :(得分:4)
你需要引用:
var position = 5;
$("#daddy > div:nth-child(" + position + ")").animate({
opacity: 0.01,
}, 500);
答案 2 :(得分:4)
尝试:
var position = 5;
$("#daddy > div:nth-child(" + position + ")").animate({
opacity: 0.01,
}, 500);