[英]Change label text on radio button selection with jQuery
I need to change the label text on a radio button when it is selected from "Set default" to "default" - How can this be done with jQuery? 从“设置默认”设置为“默认”时,我需要更改单选按钮上的标签文本-如何使用jQuery完成? I presume that you would use the class
radio-default
as the selector but I don't know much about jQuery. 我假设您将使用
radio-default
类作为选择器,但我对jQuery知之甚少。
<div class="radio-default"> <input type="radio" id="line-radio-1" name="line-radio"> <label for="line-radio-1">Set default</label> </div> <div class="radio-default"> <input type="radio" id="line-radio-2" name="line-radio"> <label for="line-radio-2">Set default</label> </div> <div class="radio-default"> <input type="radio" id="line-radio-3" name="line-radio"> <label for="line-radio-3">Set default</label> </div>
Use below script 使用以下脚本
$( "input:radio" ).click(function() {
$(':radio').each(function() {
$("#"+this.id).next().text( "Set default" );
});
$("#"+this.id).next().text( "Default" );
});
You can add an on click hadler on the radio button 您可以在单选按钮上添加一个点击式哈德勒
<input type="radio" id="line-radio-1" name="line-radio" onClick="yourFunc">
yourFunc: function(e){
$(e).next('label').text('your text');
}
you may want to reset the text on the previoused button clicked, but this can help you: 您可能想重置单击的先前按钮上的文本,但这可以帮助您:
$('.radio-default').on('click',function(){
$(this).find('label').text("set");
})
Try this 尝试这个
$('input:radio').click(function() {
$('label').text('Set default');
$(this).next('label').html('Default');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.