开发者

How would I run jquery code once a value is selected from a dropdown list?

The HTML involved is similar to this:

How would I run jquery code once a value is selected from a dropdown list?

http://i.stack.imgur.com/a88XG.png

I cannot change the html, it is auto generated开发者_如何学编程. I need to perform an event once a specific "option" is picked from the dropdown list, however at the moment I can't reference it, as nothing in the html seems to change.

For example, once changed to option 2, call an alert.

Thanks guys.


What you can do is listen for the change event with jQuery which is raised when the seletion is changed. After which you can query to see if the particular one you're interested in is selected

$(document).ready(function() {
  $('#EditForm.SR').change( function() {
    if ($('#EditForm.SR option:selected').val() === 'Option2') {
       // Option 2 is selected
    }
  });
});


Your elements' IDs have spaces in them which is not allowed:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

But you could try getting the <select> by class name:

$('select.inputControl').bind('change', function() {
  // Do what you need to here.
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜