jquery 動態 給select賦值
阿新 • • 發佈:2022-03-30
<div class="right_left"> <select id="supply"> <option>請選擇供應商</option> </select> <svg class="icon" aria-hidden="true" style="width: 15px;height: 15px;"> <use xlink:href="#iconqianwang_iocn1"></use> </svg> </div>
js
//獲取供應商的值 getSupply(){ $.ajax({ type : "post", url : "伺服器地址", async : true, data : { 'userkey' : self.userkey, 'uniqueid' : self.uniqueid }, dataType : 'json', success : function(msg) { if (msg.status == 1) { this.supplyArray = msg.result; /** 設定供應商的值 */ if(this.supplyArray.length){ $("#supply").empty(); //清空 for(var i = 0 ; i<this.supplyArray.length;i++){ $("#supply").append("<option value=" + this.supplyArray[i].id + ">" + this.supplyArray[i].name + "</option>"); //動態新增標籤 } } }else{ } } }); },