Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

drop down menu - jquery function on dropdown select

I need to run a jquery function if a certain dropdown option is selected.

<select name=dropdown size=1>
    <option value=1>option 1</option>
    <option value=2>option 2</option>
</select>

I have the commands in the function ready, Im just not sure on how to make it so if option 2 is currently active in the dropdown, then run the function.

(dropdown doesnt have a submit button, i want it ran when the user highlights the option)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this demo http://jsfiddle.net/JGp9e/

This will help, have a nice one!

code

$('select[name="dropdown"]').change(function(){

    if ($(this).val() == "2"){
        alert("call the do something function on option 2");
     }        
});?

HTML

<select name="dropdown" size=1>
    <option value="1">option 1</option>
    <option value="2">option 2</option>
</select>?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...