js中遍歷出查詢后的listmodel(下拉框系列)


function  selectclassname(){
  $.ajax({
    url:"queryschoolclasslists.action",
    async:false,
    dataType:"json",
    type:"post",
    success:function (formData) {
      var list = formData.listmodal;
      $.each(list,function(index,item){
        var sel = document.getElementById ('classname');       //確定select的id
        var option = document.createElement ('option');        //得到select的節點
        option.value = item.id;                   //select的value就是item.id
        var txt = document.createTextNode (item.classname);  //遍歷出的select中的值
        option.appendChild (txt);                   //添加
        sel.appendChild (option);                  //添加
      });
    },
    error:function (error) {
      alert("獲取單個信息失敗****" + error.status);
    }
  });
};

var classname = $("#classname").find("option:selected").text();//獲取下拉框的text

 經過方法得到listmodel集合,用$.each(index,item){}遍歷循環,其中document.getElementById('')得到select的id(確定哪個select使用這個循環)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM