使用$(this)JQuery选中输入单选按钮?
我试图设置一个要在点击按钮时检查的输入。我知道如何使用下面函数中的ID来执行此操作:使用$(this)JQuery选中输入单选按钮?,jquery,button,input,radio-button,Jquery,Button,Input,Radio Button,我试图设置一个要在点击按钮时检查的输入。我知道如何使用下面函数中的ID来执行此操作: $(".buttonsQuestion50").click(function() { $('#radio-1').prop('checked',true); }); 我试图找出如何使用$this使相同的功能正常工作。目标如下: $(".buttonsQuestion50").click(function() { $(this).prop('checked',true); }); 以这种方
$(".buttonsQuestion50").click(function() {
$('#radio-1').prop('checked',true);
});
我试图找出如何使用$this使相同的功能正常工作。目标如下:
$(".buttonsQuestion50").click(function() {
$(this).prop('checked',true);
});
以这种方式使用$this不起作用。关于如何使它工作有什么建议吗
谢谢
HTML供参考:
<div class="button-box col-lg-12 col-xs-12"><!--
--><button id="masters" type="button" class="fourButtons buttonsQuestion50 btn btn-info ">
<input class='' type="radio" name="group1" id="radio-1"> Agree </button><!--
--><button id="doctorate" type="button" class="fourButtons buttonsQuestion50 btn btn-info ">
<input class='' type="radio" name="group1" id="radio-2"> Strongly Agree </button><!--
--></div>
<div class="button-box col-lg-12 col-xs-12"><!--
--><button id="associates" type="button" class="fourButtons buttonsQuestion50 btn btn-info ">
<input class='' type="radio" name="group1" id="radio-3">Disagree</button><!--
--><button id="bachelors" type="button" class="fourButtons buttonsQuestion50 btn btn-info ">
<input class='' type="radio" name="group1" id="radio-5">Strongly Disagree </button><!--
--></div>
您可以使用方法来执行所需的操作,但标记不是W3C有效的。按钮中不应该有输入。您可以对代码进行测试验证
$.buttonsQuestion50.clickfunction{
$this.find'input[type=radio]'。prop'checked',true;
};
同意
强烈同意
不同意
强烈反对
您可以使用方法来执行所需的操作,但标记不是W3C有效的。按钮中不应该有输入。您可以对代码进行测试验证
$.buttonsQuestion50.clickfunction{
$this.find'input[type=radio]'。prop'checked',true;
};
同意
强烈同意
不同意
强烈反对
$.buttonsQuestion50和``$.buttonsQuestion50``是一样的吗?@DegenSharew这是真的。这是收音机1和$这是不同的然后你需要给我们看html@DegenSharewDoneA单选按钮内有一个按钮。。。这是个好主意吗?$.buttonsQuestion50和``$.buttonsQuestion50``是一样的吗?@DegenSharew这是真的。这是收音机1和$这是不同的然后你需要给我们看html@DegenSharewDoneA单选按钮内有一个按钮。。。这是个好主意吗?再加上一个理解问题的方法;我没意识到按钮把收音机的输入信号包起来了。这非常有帮助。谢谢你抽出时间!再加上一个用于理解问题;我没意识到按钮把收音机的输入信号包起来了。这非常有帮助。谢谢你抽出时间!