所以,当我点击提交'按钮,我有'没有'单选按钮选择“是”'单选按钮..
脚本:
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:
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>
答案 0 :(得分:1)
问题出在您的if
声明中:
if (document.getElementById('render_Yes').checked = true) {
您正在尝试将与true
进行比较,而是将属性设置为true
。 =
运算符用于分配;您正在寻找==
或===
运算符,但在这种情况下,您只需要将属性检查为布尔值:
if (document.getElementById('render_Yes').checked) {