我似乎无法弄清楚这一点。它在for 循环的第一部分工作正常,但是 var 在我评论过它中断的内部点击函数上丢失了......
另外,可能有一种更简洁的方式来编写它:
$(function () {
var a = "rgb(58,88,90)";
var b = "rgb(123,156,158)";
for (var c = 1; c <= 3; c++) {
if ($("#select" + c).is(":checked")) {
$("#select" + c + "-icon").css("background", a);
var d = document.getElementById("select" + c + "_title").innerHTML;
$("#Selection_" + c).val(d)
} else {
$("#select" + c + "-icon").css("background", b);
$("#Selection_" + c).val("Off")
}
$("#select" + c).click(function () {
// here's where it stops working... var c is no longer recognized...
if ($("#select" + c).is(":checked")) {
$("#select" + c + "-icon").css("background", a);
var d = document.getElementById("select" + c + "_title").innerHTML;
$("#Selection_" + c).val(d)
} else {
$("#select" + c + "-icon").css("background", b);
$("#Selection_" + c).val("Off")
}
})
}
return false });
这是它定位的第一对对象:
<label for="select1"><aside id="select1-icon" class="icon-form right rounded"><img src="../common/images/icon-viewDemo.png" /></aside>
<input type="checkbox" id="select1" name="select" checked="checked" class="view" /> <h5 id="select1_title">Watch Demo</h5></label>
和:
<input type="hidden" id="Selection_1" name="Selection_1" value=""/>