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使用这个循环)

 

posted @ 2016-08-19 16:27  游走的仙  阅读(3568)  评论(0编辑  收藏  举报