如何使用Jquery中的索引值检查检查列表中的任何一个选项:
for(var i in station_list)
{
if(temp==0)
{
$("#obser_location_list_label_gis_div").html("Locations:");
$("#obser_location_list_value_gis_div").html("" +
"<select id='obser_location_gis' name='obser_location_gis' multiple='multiple'>" +
"<option value='-1'>all</option>" + "</select>");
}
$("#obser_location_gis").append("<option value="+i+">"+station_list[i]+"</option>");
temp++;
}
答案 0 :(得分:0)
请看这个小提琴:
$(document).ready(function () {
//check 5th checkbox
$($('input[type="checkbox"]')[4]).trigger('click');
//OR using a loop:
//loop through all of your checkboxes..
$.each($('input[type="checkbox"]'), function (ind, val) {
//check the box that has class "checkme"
if ($(this).hasClass('checkme')) {
$($('input[type="checkbox"]')[ind]).trigger('click');
//you could also do:
/// $(this).trigger('click');
//or
/// $(this).attr('checked', 'checked');
}
});
});