How can I, using jQuery, set the "next" item of an already selected item as "selected."

如何使用jQuery设置已选择项的“下一个”项作为“selected”。

For example, if I have:

例如,如果我有:

<select>
<option value="1" >Number 1</option>
<option value="2" selected="selected">Number 2</option>
<option value="3" >Number 3</option>
<option value="4" >Number 4</option>
</select>

We can see that "Number 2" is selected, and using jQuery, I'd like to set "Number 3" as selected, and remove the selected "attribute" from "Number 2". I'm assuming I need to use the next selector, but I'm not quite sure how to implement.

我们可以看到“2号”被选中,使用jQuery,我想将“3号”设置为选中,并从“2号”中移除选中的“属性”。我假设我需要使用下一个选择器,但是我不确定如何实现。

11 个解决方案

#1


60

$('option:selected', 'select').removeAttr('selected').next('option').attr('selected', 'selected');

Check out working code here http://jsbin.com/ipewe/edit

查看这里的工作代码http://jsbin.com/ipewe/edit

更多相关文章

  1. jsf中获取属性值的普通获取和jquery获取区别
  2. bootstrap-select js jQuery控制select属性变化
  3. JQUERY组装对象并调用自身函数改变自己的属性
  4. 使用表单字段值定制CSS属性。
  5. js获取html下拉框中选中值的自定义属性值
  6. 关于INPUT的autocomplete="off" 属性(浏览器表单默认的记忆功能)
  7. HTML5新增标签与属性
  8. CSS定位属性之间的相互作用
  9. HTML:关于a标签的target属性

随机推荐

  1. android中TextAppearanceSpan的使用
  2. 沈大海移动开发课程android,j2me
  3. Android ListView 一些设置 , 去除边缘阴
  4. Android中的GridView详解
  5. Android单选框基本应用方式
  6. android WebView 开发指栏
  7. android教程资源 免费android深入浅出课
  8. Android 布局中如何使控件居中
  9. android小游戏 猜拳游戏设计
  10. Android最新开源框架大全