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