使用jquery,获取"next"消息的最佳方法是什么?具有特定类别名称的文本框 [英] Using jquery, what is the best way to get the "next" textbox with a specific class name

查看:86
本文介绍了使用jquery,获取"next"消息的最佳方法是什么?具有特定类别名称的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html页面上有一堆重复的文本框和组合框.我想在更改组合框时更改组合框下方的文本框的值.所以到目前为止我有这段代码:

i have a bunch of repeating textboxes and comboboxes on an html page. I want to change the value of the textbox below the combobox when i change the combobox. So i have this code so far:

$('.myDropdown').change(function () {
    var currentDropdownValue = $(this).val(); 
    if (currentDropdownValue == "Regular") {
         //CHANGE TEXTBOX BELOW THIS COMBOBOX WITH CLASS = "QUANTITY" TO 10.
    }
});

这是我的html

<select class="myDropdown">
 <option value="volvo">Volvo</option>
 <option value="saab">Saab</option>
 <option value="mercedes">Mercedes</option>
 <option value="audi">Audi</option>
</select>

<input class="quantity" type="text" />

基本上,我需要弄清楚正确的选择器语法,就像我在使用"Closest()"一样,但这似乎只会出现在DOM树上,而不会超出当前值.

basically, i need to figure out the right selector syntax as i was using "Closest()" but that seems to only go up the DOM tree and not past the current value.

推荐答案

您可以使用 .next()返回下一个项目,或者如果您更挑剔,则将其传递给选择器.

You could use .next() to return the next item or pass it a selector if you are more picky.

$(this).next('.quantity').val(10);

无需像parent()之类的多余的DOM遍历.

No need for extra DOM Traversing like parent() or such.

正在工作的JSFiddle: http://jsfiddle.net/CXzVe/2/.

Working JSFiddle: http://jsfiddle.net/CXzVe/2/.

这篇关于使用jquery,获取"next"消息的最佳方法是什么?具有特定类别名称的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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