function select() {
return ($('input[type=radio]:checked + label').text());
}
<div class="push-right">
<div class="radio inline">
<input class="radio ui-helper-hidden-accessible" name="fadder_applicant_type_person" id="fadder-female" title="female" value="2" type="radio" style="display: none;"><span class="ui-radio ui-radio-state-checked ui-radio-checked"></span>
<label for="fadder-female" class="ui-radio ui-radio-state-checked ui-radio-checked">
Kvinna
</label>
</div>
<div class="radio inline">
<input class="radio ui-helper-hidden-accessible" name="fadder_applicant_type_person" id="fadder-male" title="man" value="1" type="radio" style="display: none;"><span class="ui-radio"></span>
<label for="fadder-male" class="ui-radio">
Man
</label>
</div>
</div>
选择收音机但想要选择文本标签如果我选择单选按钮fadder-male
文本应该捕获“男人”
答案 0 :(得分:0)
如果您希望每次输入更改时都显示文本,请尝试以下
$('input[type=radio]').on('change',function(){
console.log($.trim($(this).siblings('label').text()));
});
答案 1 :(得分:0)
function labelValue(id){
if($("#"+id).is(':checked')){
var currlable = $("#"+id).siblings('label').text();
return currlable;
}
}
$("input[type=radio]").on("click",function(e){
var id = $(this).attr("id");
var labv = labelValue(id);
alert(labv);
});
这是工作小提琴 https://jsfiddle.net/mcyee0eg/3/
答案 2 :(得分:0)
你可能想试试这个:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<label for="demo">Demo</label>
<input type="radio" id="demo" />
<script>
$(document).ready(function(){
$("#demo").click(function(){
alert($("label[for='demo']").html());
});
});
</script>
简单的jquery代码