Home > Web Front-end > JS Tutorial > jquery trigger method to achieve linkage_jquery

jquery trigger method to achieve linkage_jquery

WBOY
Release: 2016-05-16 15:13:09
Original
1282 people have browsed it

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>

Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template