开发者

jQuery Appending Attribute to Elements That Contain The Specified Text Node

For example, I would like to append selected="selected" to the op开发者_JAVA百科tion that contains This one, which jQuery selector should be used to append attributes into that element?

<select>
    <option>Not this</option>
    <option>This one</option>
</select>

Thanks in advance!


If there are no value attributes, then the text becomes the value, so you can just use .val():

$("select").val("This one");

Or, if it has a value="something" attribute, use that instead:

$("select").val("something");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜