[英]When I try to click one radio button it selects the other
So, when I click the 'Submit' button and I have the 'no' radio button selected it selects the 'yes' radio button.. 因此,当我单击“提交”按钮并且选择了“否”单选按钮时,它选择了“是”单选按钮。
Script: 脚本:
function action() {
var name = document.getElementById('username').value;
document.getElementById("theIMG").src = "https://crafatar.com/avatars/" + name;
console.log("Working");
if (document.getElementById('render_Yes').checked = true) {
document.getElementById("renderIMG").src = "https://crafatar.com/renders/body/" + name + "?helm&scale=4";
} else {
if (document.getElementById('render_No').checked = true) {
return false;
}
}
}
HTML: HTML:
Render: <br/>
<input type="radio" name="yn" id="render_Yes" value="yes">Yes</input>
<input type="radio" name="yn" id="render_No" value="no" checked="checked">No</input> <br/> <br/>
<button id="submit" onClick="action()">Submit</button> <br />
<br />
<img id="theIMG"></img>
<img id="renderIMG"></img>
The problem is in your if
statements: 问题出在您的
if
语句中:
if (document.getElementById('render_Yes').checked = true) {
You're trying to compare to true
, but instead you're setting the property to true
. 您尝试将其与
true
进行比较 ,但您将属性设置为true
。 The =
operator is for assignment; =
运算符用于赋值; you're looking for the ==
or ===
operators, though in this case you really just need to check the property as a boolean: 您正在寻找
==
或===
运算符,尽管在这种情况下,您实际上只需要将属性检查为布尔值即可:
if (document.getElementById('render_Yes').checked) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.