[英]Why can't I get this value from the next dropdown with jQuery?
I am attempting to get the value of a dropdown menu. 我正在尝试获取下拉菜单的值。 I have several on the page.
我在页面上有几个。
The way it works is there is a radio button before each dropdown and ideally, on selecting the radio button, we simply get the current value displayed on the next select -> option. 它的工作方式是在每个下拉列表前都有一个单选按钮,理想情况下,选择单选按钮时,我们只需在下一个select->选项上显示当前值即可。
What I have so far is: 到目前为止,我有:
html: 的HTML:
<input type="radio" class="ticketOption" value="30.00" />
<select>
<option value="1">1</option>
<option value="2">2</option>
</select>
jquery: jQuery的:
$j(document).ready(function(){
$j('.ticketOption').click(function(){
var price = $j(this).attr('value');
var tickets = $j(this).next('select option:selected').text();
alert(tickets);
});
})
Yet my alert is coming up blank? 但是我的警报变得空白了吗? I'm not sure if I'm doing my next() correctly.
我不确定我是否正确地执行了next()。 It seems pretty straight forward but I seem to be like thomas edison when it comes to getting my light bulb working.
看起来很简单,但是在使灯泡工作时,我看起来就像托马斯·爱迪生。
Any ideas? 有任何想法吗?
That's because you're trying to go next()
into a option tag, which your input doesn't have. 那是因为您试图将
next()
放入一个选项标签,而您的输入没有该标签。 So you need to modify it slightly: 因此,您需要对其进行一些修改:
var tickets = $j(this).next('select').find('option:selected').text();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.