在1.4中通过jquery设置选择标签

jquery 1.3.2中,以下工作:
<select id="c">
  <option value="325">Red</option>
  <option value="833">Purple</option>
</select>

$('#c').val('Red');

并且它将选项更改为选项,并将RED作为其标签.在jQuery 1.4中,这失败了.如何在1.4中获得相同的结果?这是1.3版本中的错误吗?

解决方法

你必须这样做:
$('option:contains("Red")','#c')[0].selected = true

编辑

@Tomalak

如果标签不相互排斥,则需要重写选择器:

$.fn.labselect = function(str) {
    $('option',this).filter(function() {
       return $(this).text() == str;
    })[0].selected = true;

    return this;
};

// Use it like this
$('#c').labselect('Red');

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...