<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
window.onload = function() {
document.getElementsByTagName('input')[2].onclick =
function() {
var t1 = document.getElementsByTagName('input')[0].value;
var t2 = document.getElementsByTagName('input')[1].value;
if(!isNaN(parseInt(t1)) && !isNaN(parseInt(t2))) {
document.getElementsByTagName('input')[3].value = parseInt(t1) + parseInt(t2);
} else {
alert("请填写正确的数字");
}
}
}
</script>
</head>
<body>
<input type='text' id='txt1' />
<select id='select'>
<option value='+'>+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type='text' id='txt2' />
<input type='button' value=' = ' /> <!--通过 = 按钮来调用创建的函数,得到结果-->
<input type='text' id='fruit' />
</body>
</html>