Home > Article > Web Front-end > jquery implements a method to update the contents of a drop-down list when triggered_jquery
The example in this article describes how jquery implements the method of updating the contents of a drop-down list when triggered. Share it with everyone for your reference, the details are as follows:
If the server has a request address to return the required data
url:/hello
Returns something like:
html:
Button: 281ce987ab40a99840e384e87fddb38a
Drop-down list:28aacf2a2a285412e07f89f779e8c8c918bb6ffaf0152bbe49cd8a3620346341
js code:
$(function(){ $("#btn").click( $.ajax({ type:"POST", url:"http://localhost/XXXX/Test", cache: false,//不缓存 dataType:"json",//返回数据格式 success:function(ret){ $("#sel").empty(); $.each(ret,function(ind){ for(var key in ret[ind]){ var opt = $("<option></option>"); opt.val(ret[ind][key]); opt.text(key); $("#sel").append(opt); } }); } }); ); });
I hope this article will be helpful to everyone in jQuery programming.