獲取select 中的option屬性的值和循環出來的Id

    var chengshi=document.getElementById("chengshixuanze");//select標籤的id
        chengshi.onchange=function(){                                       //當選項改變時觸發
            var valOption=this.options[this.selectedIndex].value;//獲取option的value
                alert(valOption);
            var id=this.options[this.selectedIndex].id;//獲取option的id(能夠得到循環出來的Id)
                alert(id);
            var txtOption=this.options[this.selectedIndex].innerHTML;//獲取option中間的文本
                alert(txtOption);

       } html


//分配html頁面的城市 app

 aj.post('provinceid='+id,"<{$url}>/area",function(msg){
var arr=eval('('+msg+')');
var len=arr.length;
var ci=document.getElementById('ci');
for(var i=0;i<len;i++){
//document.write('<option>'+arr[i]+'</option>');
//alert(arr[i]);
var opt=document.createElement("option");
opt.value=arr[i];
opt.innerHTML=arr[i];
opt.id=i;
ci.appendChild(opt);
}
})
post

相關文章
相關標籤/搜索