开发者

Jquery Dropdownlist Select Change

开发者 https://www.devze.com 2023-01-08 15:13 出处:网络
RED BLACK BLUE WHITE PINK i not to want $(\'#COLOR\').val(2); i want $(\'#COLOR\').val(\'RED\'); How to make ?

RED BLACK BLUE WHITE PINK

i not to want $('#COLOR').val(2);

i want $('#COLOR').val('RED');

How to make ?

Thank开发者_高级运维 You.


To select by value, pass that into the .val(newValue) call, like this:

$('#COLOR').val('0');

This will select "RED" because it has value="0" for it's <option> element.


For the updated question: to select by text there are a few approaches, for example:

$("#COLOR").val(function() {
  return $('option', this).filter(function() { 
    return this.innerHTML == 'RED'; 
  }).attr('value');
});

You can give it a try here. ​


Can you make the value "RED", which will allow you to do what you want? Or do you have to keep the same HTML. For example

<option value="RED">RED</option>
0

精彩评论

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