<script type='text/javascript'>
function showUserGroupNotHaveAut(map){
var alloptionValue=""
var alloptiontext=""
alert(map);
if(map!=null){
var temp=new Array()
temp[temp.length]='<select name="list2" size="10" multiple class="option" id="listnotaut"> '
for(var i in map){
temp[temp.length]="<option value='"
temp[temp.length]=i
alloptionValue=alloptiontext+i+","
temp[temp.length]="'>"
temp[temp.length]=map[i]
alloptiontext=alloptiontext+map[i]+","
temp[temp.length]="</option>"
}
temp[temp.length]="</select>"
document.getElementById("nothaveaut").innerHTML=temp.join("")
}
alert(alloptionValue)//注意、都是用,分割,结尾多一个,,在后台取字符串,然后用split分割
alert(alloptiontext)
}
</script>
我还有一次对这个生成的select
进行添加删除option的操作
对一个已经存在的select
我要拿到select中所有的option
function getAllHavaAut(){
var as= document.getElementById("listaut").options
alert(as);
}
这里拿到了一个obj 用循环遍历 会报错
我不知道该怎么办
js没有接触过
var as= document.getElementById("listaut").options;
var str="";
for(var i=0;i<as.length;i++)
{
str="Option显示的文本为\t"+as[i].text+"\noption的value为\t"+as[i].value;
alert(str);
}
}
function getAllHavaAut(){
var as= document.getElementById("listaut").options;
var str="";
for(var i=0;i<as.length;i++)
{
str+=as[i].value+",";
}
alert(str);
}
谢谢
为什么我遍历的时候就报错?
不明白
for(int i=0;i <as.length;i++)
我郁闷
刚开始学js的话都会碰到这个int问题的.
我开始的话也常用int来声名变量.