JQuery使用索引值手动检查下拉列表

时间:2014-03-10 13:02:02

标签: jquery dropdownchecklist

如何使用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++;
}

1 个答案:

答案 0 :(得分:0)

请看这个小提琴:

http://jsfiddle.net/K4E79/

$(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');

    }
});
});