The example in this article describes the method of jquery trigger to achieve linkage. Share it with everyone for your reference, the details are as follows:
<html> <head> <title>testing</title> <script src="jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $("#Provinces").change(function (e,cityValue) { if ($(this).val() == "1") { $("#City").html("<option value='1' >长沙</option><option value='2' >衡阳</option>"); } else { $("#City").html("<option value='1' >武汉</option><option value='2' >襄阳</option>"); } if (typeof (cityValue) != "undefined") { $("#City").val(cityValue); } }); }); function test() { $("#Provinces").val("2"); $("#Provinces").trigger("change","2"); } </script> </head> <body> 省: <select id="Provinces" > <option value="1" >湖南</option> <option value="2" >湖北</option> </select><br /> 市: <select id="City"> <option value="1" >长沙</option> <option value="2" >衡阳</option> </select><br /> <input type="button" value="设置成湖北襄阳" onclick="test()" /> </body> </html>
As we all know, trigger is asynchronous, and the code executed after it may run in front of it. The above code avoids this.
Readers who are interested in more jQuery-related content can check out the special topics on this site: "JQuery drag effects and skills summary", "jQuery extension skills summary", "JQuery common classic special effects summary", "jQuery animation and special effects usage summary", "jquery selector usage summary" and "jQuery common plug-ins and usage Summary》
I hope this article will be helpful to everyone in jQuery programming.