Example of a jquery event code triggered after an HTML select option selection

Source: Internet
Author: User
<span id="Label3"></p><p><p>The page design was originally made By:</p></p><p><p>Because many customers do not know how to come to our company, the leader wants me to make a link on the public number above, the customer can open the map directly through the public number and navigate to our Company's office Location.</p></p><p><p>Implementation is not difficult, but because the company has a lot of offices, so need to design a menu, after the user selects the corresponding office automatically load the relevant map, so I made the following page:</p></p><p><p>(little brother, If the code is redundant or you have a better writing also please correct me, thank you!) The bottom has posted the original code! )</p></p><p><p></p></p><p><p></p></p><p><p>So how do I write a trigger event in select?</p></p><p><p>There are several ways to do this:</p></p><p><p>Method one, the Pure JS code:</p></p><pre class="brush:html;gutter:true;"><pre class="brush:html;gutter:true;"><select id= "addr" onchange= "sele_change ()" > <option id= "1" value= "address 1" > Location 1</a> < Option id= "2" value= "address 2" > Location 2</a></select><script type= "text/javascript" > function sele_ Change () { var objs = document.getElementById ("addr"); var get_map = objs.options[objs.selectedindex].value; Alert (get_map); Events that need to be executed (load map Html) }</script></pre></pre><p><p></p></p><p><p>Method two, using jquery code: (this is the online search instance, the principle is the same, this is the first to get the Val value of option, and then display the value in the #thediv, the idea is consistent, a little change of code can be made to load the map Effect)</p></p><pre class="brush:html;gutter:true;"><pre class="brush:html;gutter:true;"><script type= "text/javascript" src= "jquery/jquery.js" ></script><script type= "text/javascript" > $ (document). Ready (function () { $ ("#sel"). bind (' change ', function () { if ($ (this). val () ==0) { return; } else{ $ ("#thediv"). Text ($ (this). val ());});}) ; </script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.