About Select drop-down box selection trigger event

Source: Internet
Author: User

I have always believed that the Select drop-down box selects the option options to use the OnClick register event, as follows:

<select>
    <option value= "0" onclick= "func (0)" > option one </option>
    <option value= "1" onclick= " Func (1) "> Options two </option>
</select>

Today there is a request to do linkage menu, that is, every point, the adjacent drop-down box will automatically change, I think no problem ah, onclick walk

So go above the route, the customer also said, IE8 must support, I think also, XP of IE kernel can only ascend to IE8, now many users still

Reluctant XP, but it supports the onclick ah, I tried under FF, a little problem no, but a switch IE8, tell you, a little reaction did not

And then find the data, the original select its event is registered on its own label, not the onclick, but onchange, sub-tags on the low version of the browser is not valid, but also not the formal standard of writing.

<select onchange= "func () >
    <option value=" 0 "> Option one </option>
    <option value=" 1 "> Option two </option>
</select>
OK, here's the question again, what about the parameters I preach? How to receive Parameters

It's not a problem, jquery gives you the answer

function func () {
 //Gets the selected option label
 var vs = $ (' Select  option:selected '). Val ();

Of course, the select here is better to add an ID to confuse, OK, problem solving, up posture of the wood has it, haha ...




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.