我想使用如下所示的文本 5 和 6。我无法修改 html,因为它是自动生成的,并且还有许多其他具有相同结构的 radio 。我如何使用 jQuery 或 JavaScript 来实现这一点并将它们存储为变量。
<label class="radio">
<label style="display: none;">
<input type="radio" name="x_keeper1_price" id="x_keeper1_price_0" value="21"/>
</label>
5
</label>
<label class="radio">
<label style="display: none;">
<label style="display: none;">
<input type="radio" name="x_Defd5_price" id="x_Defd5_price_0" value="28"/>
</label>
</label>
6
</label>
最佳答案
如果单选按钮后的文本是 html 代码,这是一个更好的解决方案:
var text = $("#x_keeper1_price_0") //the radio button
.closest("label.radio") //the label with class=radio)
.html() //the html code
.replace(/<label[\d\D]+<\/label>/, '');
/* Removing the "second" label and its content.
That will get the text after the radio button. */
alert(text);
jsfiddle:http://jsfiddle.net/72KcV/3/
关于javascript - 我想使用 radio 输入的文本。我如何使用 jQuery 或 JavaScript 获取它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22882214/