請問為什么在點(diǎn)擊調(diào)用函數(shù)后返回的sum值只是p1呢
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數(shù)調(diào)用</title>
? ?<script type="text/javascript">
? ? ? function contxt() //定義函數(shù)
? ? ? {
? ? ? ? ?var? {?
? ? ? ? ? ? ?Int p1 = document.getElementById("1").value;
? ? ? ? ? ? ?Int p2 = document.getElementById("2").value;
? ? ? ? ? ? ?Int sum = p1 + p2;
? ? ? ? ?}
? ? ? ? ? ? ?document.write(sum);
? ? ? ? ?alert("哈哈,調(diào)用函數(shù)了!");
? ? ? }
? ?</script>
</head>
<body>
? ?<form>
? ? ? ?<input type="text" id="1"/>
? ? ? ?<input type="text" id="2"/>
? ? ? <input type="button"? value="點(diǎn)擊我" onclick="? contxt()? " />??
? ?</form>
</body>
</html>
2019-03-05
老哥,這是js不是java,要拿到input框的內(nèi)容可以用value拿到
2019-02-25
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函數(shù)調(diào)用</title>
? ?<script type="text/javascript">
? ? ? function contxt() //定義函數(shù)
? ? ? {
? ? ? ??
? ? ? ? ? ? ?var p1 = Number(document.getElementById("1").value);
? ? ? ? ? ? ?var p2 = Number(document.getElementById("2").value);
? ? ? ? ? ? ?var sum = p1 + p2;
? ? ??
? ? ? ? ? ? ?document.write(sum);
? ? ? ? ?alert("哈哈,調(diào)用函數(shù)了!");
? ? ? }
? ?</script>
</head>
<body>
? ?<form>
? ? ? ?<input type="text" id="1"/>
? ? ? ?<input type="text" id="2"/>
? ? ? <input type="button"? value="點(diǎn)擊我" onclick="? contxt()? " />??
? ?</form>
</body>
</html>
2019-01-28
function里面的格式錯(cuò)了
還有這樣輸出的結(jié)果是字符連接串 不是數(shù)字計(jì)算