JS 加法运算
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script>
onload = function () {
document.getElementById('btnAdd').onclick = function () {
var add1 = document.getElementById('add1').value;
var add2 = document.getElementById('add2').value;
document.getElementById('answer').value = parseInt(add1) + parseInt(add2);
}
};
</script>
</head>
<body>
<input type="text" name="name" value="" id="add1" />+
<input type="text" name="name" value="" id="add2" />=
<input type="text" name="name" value="" id="answer" />
<input type="button" name="name" value="+" id="btnAdd"/>
</body>
</html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script>
onload = function () {
document.getElementById('btnAdd').onclick = function () {
var add1 = document.getElementById('add1').value;
var add2 = document.getElementById('add2').value;
document.getElementById('answer').value = parseInt(add1) + parseInt(add2);
}
};
</script>
</head>
<body>
<input type="text" name="name" value="" id="add1" />+
<input type="text" name="name" value="" id="add2" />=
<input type="text" name="name" value="" id="answer" />
<input type="button" name="name" value="+" id="btnAdd"/>
</body>
</html>