jquery 操作select控件 遍历option

1 判断checkbox   是否被选中

var isSmToggle = $("#isSmToggle").attr("checked");

2 获取下拉列表的选中的值,其中taskListSrc是checklist的id

var select = $("#taskListSrc option:selected").val();  //获取selected的值

3 将下拉列表选中的项置为不可编辑

$('#taskListSrc option:selected').attr("disabled", true);

4 向下拉列表中添加一项,select是要添加的项

$('#taskListTarget').append('<option>' + select + '</option>');

5 清空下拉列表

$('#taskListTarget').empty();

6 设置指定内容项为选中

$("#select_id option[text='content']").attr("selected", true); 

7 设置Select索引值为1的项选中

$("#select_id ").get(0).selectedIndex=1;  //设置Select索引值为1的项选中

8 遍历option

                    existOptText = $("selectId option").each(function() {  
                        var op = $(this).text();
                        ... // do with op
                    });











你可能感兴趣的:(jquery 操作select控件 遍历option)