使用jQuery更改选定的索引 [英] Change selected index using jquery

查看:92
本文介绍了使用jQuery更改选定的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您需要在更改另一个索引时更改a的选定索引. 例子: 我有

Hi need to change the selected index of a when another has been changed.. Example: i have

<select id="selector">
<option>No 1</option>
<option>No 2</option>
</select>
<select id="selected">
<option>ONE</option>
<option>TWO</option>
</select>

现在我希望$ selector的索引更改时$ selected索引也发生更改.例如,当我更改为"No 2"时,另一个组合框将更改为"TWO".请原谅我新手问题,但我对jquery ^^

now i want the $selected index to change when the #selector's index is changed.. like when i change to "No 2" the other combobox will change to "TWO". pardon me for newbie question but im new to jquery ^^

推荐答案

$('#selector').change(function() {
    var idx = this.selectedIndex;        
    $("select#selected").prop('selectedIndex', idx);  
});

这篇关于使用jQuery更改选定的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆