这是运行良好,但如果所有输入值的总和不等于百并停止在同一页上,我想显示警报消息。我想显示警报讯息
function doMath(){
// Capture the entered values of two input boxes
var my_input1 = document.getElementById('my_input1').value;
var my_input2 = document.getElementById('my_input2').value;
var my_input3 = document.getElementById('my_input3').value;
var my_input4= document.getElementById('my_input4').value;
var my_input5 = document.getElementById('my_input5').value;
var my_input6 = document.getElementById('my_input6').value;
// Add them together and display
var sum = parseInt(my_input1) + parseInt(my_input2) + parseInt(my_input3) + parseInt(my_input4) + parseInt(my_input5) + parseInt(my_input6);
document.write(sum);
}
<input type="text" id="my_input1" /></br>
<input type="text" id="my_input2" /></br>
<input type="text" id="my_input3" /></br>
<input type="text" id="my_input4" /></br>
<input type="text" id="my_input5" /></br>
<input type="text" id="my_input6" />
<input type="button" value="Add Them Together" onclick="doMath();" />
警报的详细信息( '嗨!良好的编码') ; – Roy
测试你的价值[if else](https://www.w3schools.com/js/js_if_else.asp),然后使用[Alert](https://www.w3schools.com/jsref/met_win_alert.asp) –
你可能会想避免使用'document.write' [页面加载完成后](http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice)。 –