无法使用Javascript或Jquery检查单选按钮
我需要一个帮助。我需要检查单选按钮并使用Javascipt/Jquery设置其值。我在下面解释我的代码无法使用Javascript或Jquery检查单选按钮,javascript,jquery,html,Javascript,Jquery,Html,我需要一个帮助。我需要检查单选按钮并使用Javascipt/Jquery设置其值。我在下面解释我的代码 <input type="radio" name="answer_type0" id="answer_type0" value="" onClick="selectScale();">Male <button type="button" id="btn">Edit</button> <script > docume
<input type="radio" name="answer_type0" id="answer_type0" value="" onClick="selectScale();">Male
<button type="button" id="btn">Edit</button>
<script >
document.getElementById('btn').onclick=function(){
var qdata='123';
$('#answer_type0[value="' + qdata + '"]').prop('checked', true).trigger('click');
//$('#answer_type0').prop("checked",true);
console.log('checked',$("#answer_type0").prop("checked"));
}
function selectScale(){
console.log('value');
}
</script>
男性
编辑
document.getElementById('btn')。onclick=function(){
var qdata='123';
$(“#回答_type0[value=“”+qdata+“]”)。prop('checked',true)。trigger('click');
//$('#答案类型0').prop(“选中”,为真);
console.log('checked',$)(“#answer_type0”).prop('checked”);
}
函数selectScale(){
console.log('value');
}
在上面的代码上,当用户单击编辑
按钮时,应选中单选按钮,并应触发单击
。但就我而言,事情不是这样发生的。普朗克来了。请帮帮我。这是答案
<input type="radio" name="answer_type0" id="answer_type0" value="" onClick="selectScale();">Male
<button type="button" id="btn">Edit</button>
<script>
document.getElementById('btn').onclick = function() {
var qdata = '0';
$('[name=answer_type' + qdata + ']').prop('checked', true).trigger('click');
console.log('checked', $("#answer_type0").prop("checked"));
}
function selectScale() {
var qdata = '0';
$('[name=answer_type' + qdata + ']').val('some_value');
console.log('some_value');
}
</script>
男性
编辑
document.getElementById('btn')。onclick=function(){
var qdata='0';
$('[name=answer_type'+qdata+']')。prop('checked',true)。trigger('click');
console.log('checked',$)(“#answer_type0”).prop('checked”);
}
函数selectScale(){
var qdata='0';
$('[name=answer_type'+qdata+']').val('some_value');
console.log('some_value');
}
以下是答案
<input type="radio" name="answer_type0" id="answer_type0" value="" onClick="selectScale();">Male
<button type="button" id="btn">Edit</button>
<script>
document.getElementById('btn').onclick = function() {
var qdata = '0';
$('[name=answer_type' + qdata + ']').prop('checked', true).trigger('click');
console.log('checked', $("#answer_type0").prop("checked"));
}
function selectScale() {
var qdata = '0';
$('[name=answer_type' + qdata + ']').val('some_value');
console.log('some_value');
}
</script>
男性
编辑
document.getElementById('btn')。onclick=function(){
var qdata='0';
$('[name=answer_type'+qdata+']')。prop('checked',true)。trigger('click');
console.log('checked',$)(“#answer_type0”).prop('checked”);
}
函数selectScale(){
var qdata='0';
$('[name=answer_type'+qdata+']').val('some_value');
console.log('some_value');
}
像这样试试
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="style.css" />
<script data-require="jquery" data-semver="3.0.0" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
</head>
<body>
<input type="radio" name="answer_type0" id="answer_type0" value="" onClick="selectScale();">Male
<button type="button" id="btn">Edit</button>
<script >
$(document).ready(function(){
document.getElementById('btn').onclick=function(){
$('#answer_type0').prop("checked",true);
}
function selectScale(){
console.log('value');
}
});
</script>
</body>
</html>
男性
编辑
$(文档).ready(函数(){
document.getElementById('btn')。onclick=function(){
$('#答案类型0').prop(“选中”,为真);
}
函数selectScale(){
console.log('value');
}
});
像这样试试
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="style.css" />
<script data-require="jquery" data-semver="3.0.0" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
</head>
<body>
<input type="radio" name="answer_type0" id="answer_type0" value="" onClick="selectScale();">Male
<button type="button" id="btn">Edit</button>
<script >
$(document).ready(function(){
document.getElementById('btn').onclick=function(){
$('#answer_type0').prop("checked",true);
}
function selectScale(){
console.log('value');
}
});
</script>
</body>
</html>
男性
编辑
$(文档).ready(函数(){
document.getElementById('btn')。onclick=function(){
$('#答案类型0').prop(“选中”,为真);
}
函数selectScale(){
console.log('value');
}
});
是否可以更正此问题?在选择器中,您希望输入有一个值属性,但它没有。请检查此项。我也尝试了您所做的操作。单击时,我还需要设置其值。在这种情况下,它不会出现。4小时前,出现了完全相同的问题。你能纠正这个问题吗?在选择器中,你希望输入有一个值属性,但它没有。检查此项我也尝试了你所做的。我需要在单击时设置其值。在这种情况下,它不会出现。4小时前,有一个完全相同的问题,请在我的plunkr内测试。不工作?你能解释一下什么不起作用吗?这里是JSFIDLE:好的,但我还需要动态设置它的值。告诉我您想在哪里设置值?解释更多检查这一行“$”#回答_type0[value=“”+qdata+“]”)。prop('checked',true)。trigger('click');`从我的代码。请在我的plunkr内测试。不工作?你能解释一下什么不起作用吗?这里是JSFIDLE:好的,但我还需要动态设置它的值。告诉我您想在哪里设置值?解释更多检查这一行“$”#回答_type0[value=“”+qdata+“]”)。prop('checked',true)。trigger('click');`从我的代码。