我想用收音机输入文字。如何使用jQuery或JavaScript获得它
我想使用下面显示的文本5和6。我不能修改html,因为它是自动生成的,而且还有许多其他收音机具有相同的结构。如何使用jQuery或JavaScript实现这一点,并将它们存储为变量我想用收音机输入文字。如何使用jQuery或JavaScript获得它,javascript,jquery,html,radio,Javascript,Jquery,Html,Radio,我想使用下面显示的文本5和6。我不能修改html,因为它是自动生成的,而且还有许多其他收音机具有相同的结构。如何使用jQuery或JavaScript实现这一点,并将它们存储为变量 <label class="radio"> <label style="display: none;"> <input type="radio" name="x_keeper1_price" id="x_keeper1_price_0" value="21"/&g
<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>
5.
6.
您可以执行以下操作
$('.radio').text()
请参见此处的工作解决方案:
因为我们使用一个类来选择文本,所以您可能希望在选择器上循环,并对每个值执行类似的操作
var items = $('.radio');
$.each(items, function(i, item) {
var text = $(item).text();
//do something with text
});
您可以执行以下操作
$('.radio').text()
请参见此处的工作解决方案:
因为我们使用一个类来选择文本,所以您可能希望在选择器上循环,并对每个值执行类似的操作
var items = $('.radio');
$.each(items, function(i, item) {
var text = $(item).text();
//do something with text
});
您可以执行以下操作
$('.radio').text()
请参见此处的工作解决方案:
因为我们使用一个类来选择文本,所以您可能希望在选择器上循环,并对每个值执行类似的操作
var items = $('.radio');
$.each(items, function(i, item) {
var text = $(item).text();
//do something with text
});
您可以执行以下操作
$('.radio').text()
请参见此处的工作解决方案:
因为我们使用一个类来选择文本,所以您可能希望在选择器上循环,并对每个值执行类似的操作
var items = $('.radio');
$.each(items, function(i, item) {
var text = $(item).text();
//do something with text
});
如果单选按钮后的文本是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);
var text=$(“#x_keeper1_price_0”)//单选按钮
.closest(“label.radio”)//class=radio的标签)
.html()//html代码
.替换(/如果单选按钮后的文本是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);
var text=$(“#x_keeper1_price_0”)//单选按钮
.closest(“label.radio”)//class=radio的标签)
.html()//html代码
.替换(/如果单选按钮后的文本是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);
var text=$(“#x_keeper1_price_0”)//单选按钮
.closest(“label.radio”)//class=radio的标签)
.html()//html代码
.替换(/如果单选按钮后的文本是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);
var text=$(“#x_keeper1_price_0”)//单选按钮
.closest(“label.radio”)//class=radio的标签)
.html()//html代码
.replace(/对于此特定标记,可以使用以下jQuery代码:
$('label.radio').each(function(){
console.log($(this).contents()[2].nodeValue)
});
对于此特定标记,可以使用以下jQuery代码:
$('label.radio').each(function(){
console.log($(this).contents()[2].nodeValue)
});
对于此特定标记,可以使用以下jQuery代码:
$('label.radio').each(function(){
console.log($(this).contents()[2].nodeValue)
});
对于此特定标记,可以使用以下jQuery代码:
$('label.radio').each(function(){
console.log($(this).contents()[2].nodeValue)
});
即使这样做得到了结果,但它非常长,并且在parent().parent().parent()
方面不可读。最终,下一个开发人员将不得不猜测父项是什么。使用最接近的()而不是parent()@Zword为什么?有什么区别?@user3132718使用“最近”的优点是,如果html结构发生了变化,并且在两者之间输入了新元素,调用多个父元素将指向错误的父元素。使用。无论以后添加了什么其他子元素,最近的将始终命中预期目标尽管这样做不会得到结果,但它很长,而且在parent().parent().parent()
方面不可读。最终,下一个开发人员将不得不猜测什么是parent。请使用最近的()而不是parent()@Zword为什么?有什么区别?@user3132718使用“最近”的优点是,如果html结构发生了变化,并且在两者之间输入了新元素,调用多个父元素将指向错误的父元素。使用。无论以后添加了什么其他子元素,最近的将始终命中预期目标尽管这样做不会得到结果,但它很长,而且在parent().parent().parent()
方面不可读。最终,下一个开发人员将不得不猜测什么是parent。请使用最近的()而不是parent()@Zword为什么?有什么区别?@user3132718使用“最近”的优点是,如果html结构发生了变化,并且在两者之间输入了新元素,调用多个父元素将指向错误的父元素。使用。无论以后添加了什么其他子元素,最近的将始终命中预期目标尽管这样做不会得到结果,但它很长,而且在parent().parent().parent()
方面不可读。最终,下一个开发人员将不得不猜测什么是parent。请使用最近的()而不是parent()@Zword为什么?有什么区别?@user3132718使用“最近”的优点是,如果html结构发生了变化,并且在两者之间输入了新元素,调用多个父元素将指向错误的父元素。使用。无论以后添加了什么其他子元素,最近的将始终命中预期目标N