神啊,让alert只弹出一次吧 js的alert
<!DOCTYPEhtml><htmllang="zh-cn"><head><metacharset="UTF-8"><title>test</title></head>...
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<form name="form1">
<input id="zhuengshu1" name="A2" type="text" value="" />
<input id="zhuengshu2" name="A3" type="text" value=""/>
结果<input id="zhengshuzs" name="A4" type="text" value="" onfocus="sum();"/>
</form>
<script>
function sum(){
var n2 = document.getElementById("zhuengshu1").value;
var n3 = document.getElementById("zhuengshu2").value;
var n8=document.getElementById("zhengshuzs").value = Number(n2)+Number(n3);
alert(n8);
}
</script>
</html> 展开
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<form name="form1">
<input id="zhuengshu1" name="A2" type="text" value="" />
<input id="zhuengshu2" name="A3" type="text" value=""/>
结果<input id="zhengshuzs" name="A4" type="text" value="" onfocus="sum();"/>
</form>
<script>
function sum(){
var n2 = document.getElementById("zhuengshu1").value;
var n3 = document.getElementById("zhuengshu2").value;
var n8=document.getElementById("zhengshuzs").value = Number(n2)+Number(n3);
alert(n8);
}
</script>
</html> 展开
1个回答
展开全部
既然有文本框,为啥还要alert?
<script>
function sum(){
var n2 = document.getElementById("zhuengshu1").value;
var n3 = document.getElementById("zhuengshu2").value;
document.getElementById("zhengshuzs").value = Number(n2)+Number(n3);
}
</script>
追问
在做测试,想要输入之后看到弹窗数字,确定是否触发了。然后就遇到这个问题了
追答
那可以根据输出的文本框是否为空来判断是不是首次点击:
<script>
function sum(){
var n2 = document.getElementById("zhuengshu1").value;
var n3 = document.getElementById("zhuengshu2").value;
var n8 = Number(n2)+Number(n3);
var zs = document.getElementById("zhengshuzs");
if(!zs.value)alert(n8);
zs.value = n8;
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询