您的位置:首页 > Web前端 > HTML

html 循环输出 select 下拉列表选项

2018-01-15 00:00 597 查看
1.示例

//遍历option和添加、移除option
function changeShipMethod(shipping){
var len = $("select[name=ISHIPTYPE] option").length
if(shipping.value != "CA"){
$("select[name=ISHIPTYPE] option").each(function(){
if($(this).val() == 111){
$(this).remove();
}
});
}else{
$("<option value='111'>UPS Ground</option>").appendTo($("select[name=ISHIPTYPE]"));
}
}

2.示例

function removeOption(){
/* var x=document.getElementById("userType");
var text=x.text;
alert(text);
x.remove(x.selectedIndex); */
//alert("aa");

//var len = $("select[name=userType] option").length;

$("select[name=roleId] option").each(function(){
if($(this).text() != '小区管理员'){
//alert($(this).text());
$(this).remove();
}
});

//$("#userType option[text='超级管理员']").remove(); //删除Select中Text='超级管理员'的Option
}

资料路径:
https://www.cnblogs.com/yaoshiyou/archive/2010/08/24/1806939.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息