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
});
本文详细介绍了如何在网页中通过JavaScript操作下拉列表和选择框,包括判断状态、获取选中项、禁用编辑、添加新选项、清空列表、设置特定项为选中以及遍历选项等基本技巧。
132

被折叠的 条评论
为什么被折叠?



