This article analyzes the implementation method of jQuery select automatic selection function. Share it for your reference, as follows:
//filtervar typeid = "<!--{$typeid}-->"; var bigclassid = "<!--{$bigclassid}-->"; var smallclassid = "<!--{$smallclassid}-->"; $("#typeid option[value="+typeid+"]").attr("selected",true); $("#typeid").change(); $("#bigclassid option[value="+bigclassid+"]").attr("selected",true); $("#bigclassid").change(); $("#smallclassid option[value="+smallclassid+"]").attr("selected",true);
After obtaining the value, the settings are automatically selected.
After selection, call the change() method. The change method will display the next level select box. Then select and call the change() method. This will display all the three-level select boxes and are selected by default.
$(document).ready(function(){ //ajax cascade $("#typeid").change(function(){ var id = $(this).val(); setbigclass(id); }); $("#bigclassid").change(function(){ var id = $(this).val(); setsmallclass(id); }); $("#screen_submit").click(function(){ $("#screenform").submit(); }); }); function setbigclass(id){ var res = ajaxgetbigclass(id); if(res){ myobj = eval(res); var strHtml="<option value=0>All major categories</option>"; for(var i=0;i<;i++){ strHtml+="<option value='"+myobj[i].id+"'>"+myobj[i].name+"</option>"; } $("#bigclassid").html(strHtml); $("#bigclassid").show().change(); }else{ $("#bigclassid").html('<option value=""></option>').hide(); $("#smallclassid").html('<option value=""></option>').hide(); } } function setsmallclass(id){ var res = ajaxgetsmallclass(id); if(res){ myobj = eval(res); var strHtml="<option value=0>All subcategories</option>"; for(var i=0;i<;i++){ strHtml+="<option value='"+myobj[i].id+"'>"+myobj[i].name+"</option>"; } $("#smallclassid").html(strHtml); $("#smallclassid").show(); }else{ $("#smallclassid").html('').hide(); } }
For more information about jQuery, please visit the special topic of this site:Summary of jQuery form (form) operation skills》、《Summary of commonly used plug-ins and usages of jQuery》、《Summary of jQuery extension skills》、《Summary of jQuery switching effects and skills》、《Summary of jQuery traversal algorithm and skills》、《Summary of common classic effects of jQuery》、《Summary of jQuery animation and special effects usage"and"Summary of jquery selector usage》
I hope this article will be helpful to everyone's jQuery programming.