我是 JavaScript 的新手,希望你能帮助我,就像在主题中一样,null 属性。
var add = document.getElementById('addition').checked;
var subs = document.getElementById('substraction').checked;
var multi = document.getElementById('multiplication').checked;
var div = document.getElementById('division').checked;
var result = 0;
var x = parseInt(document.getElementById('firstNumber').value);
var y = parseInt(document.getElementById('secondNumber').value);
function calculator()
{
if (add)
{
result = addition(x, y);
}
else if (subs)
{
result = substraction(x, y);
}
else if (multi)
{
result = multiplication(x, y);
}
else if (division)
{
result = division(x, y);
};
}
<fieldset>
<legend>Method</legend>
<p><label><input type="radio" name="method" id="addition" />Addition</label></p>
<p><label><input type="radio" name="method" id="substraction" />Substraction</label></p>
<p><label><input type="radio" name="method" id="multiplication" />Multiplication</label></p>
<p><label><input type="radio" name="method" id="division" />Division</label></p>
</fieldset>
<input type="submit" value="Submit" onclick="calculator();" />
他们我收到消息“未捕获的类型错误:无法读取空 index.html:24 的属性'已检查'(匿名函数)”
请帮我。问候!