Mic*_*ael 6 jquery text radio-button checked
如标题中所述,例如:
<input id="User_Type_0" type="radio" name="User_Type" value="1" checked="checked" />
<label for="User_Type_0">User1</label>
<input id="User_Type_1" type="radio" name="User_Type" value="2" />
<label for="User_Type_1">User2</label>
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到文字:用户1
Dar*_*rov 17
$( '输入:单选:检查')的兄弟姐妹( '标签:第一').HTML()
更新:
正如Victor在评论部分所指出的那样,前一个选择器将始终选择第一个标签.在接下来的功能应该工作:
$('input:radio:checked').next('label:first').html()
Run Code Online (Sandbox Code Playgroud)
这个怎么样?
var forLabel = $('input:radio:checked').attr("id");
$("label[for='" + forLabel + "']").text();
Run Code Online (Sandbox Code Playgroud)