开发者

jquery undisable list onselect

开发者 https://www.devze.com 2023-01-06 16:58 出处:网络
I have a开发者_运维知识库 list of options dependent on what is selected in the first option. How can I make it so that after they select location the second options only displays options avaliable to

I have a开发者_运维知识库 list of options dependent on what is selected in the first option. How can I make it so that after they select location the second options only displays options avaliable to that location?

Right now I have a bunch of

<option class=2 DISABLED>Blah</option>

jQuery Code

$(document).ready(function() {
  $('#location').change(function() {
    $(.$(this).val()).removeAttr('disabled');
  });
});

The value of the location option is = to the class of the second. But it doesn't seem to work?


The selector needs to be in quotes.

$('.' + $(this).val()).removeAttr('disabled');


For sanitys sake I would change around that selector to something along the lines of:

$(document).ready(function() {
  $('#location').change(function() {
    var curLoc = $(this).val();
    $('.' + curLoc).removeAttr('disabled');
  });
}); 

Edit- Per Jon Cram <option disabled> is acceptable in non-xhtml doctypes.

0

精彩评论

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

关注公众号