语过添情 2010-02-12 01:39:15
源代码:
//--------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>计算器</title>
<script type="text/javascript">
function start(a)
{
var shuju=document.getElementById("shuju").value;
var num1;
switch(a){
case 1:
num1=Math.round(shuju);
break;
default:
alert("wu");
}
document.getElementById("show").value=num1;
}
function a(){
alert("你好!");
}
</script>
</head>
<body>
原始数据输入:<input type="text" id="shuju"></input><br/>

<button onclick="start(1)">取整(四舍五入)</button>
<input type="button" value="取整(四舍五入)" onclick="start(1)"></input><br/>

运算结果:<input type="text" id="show"></input>
</body>
</html>

//--------------------------------------------------------------
一个用button标签,另一个用input type="button"
前者可以正常使用onclick,而后者却不会有前者的结果。
当我把<input type="button" value="取整(四舍五入)" onclick="a()"></input>却可以调用a()函数,那为什么不能调用start()函数呢?

要怎么做能使<input type="button">调用start()函数呢?
...全文
9941 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
语过添情 2010-02-14
  • 打赏
  • 举报
回复
引用 4 楼 zswang 的回复:
<input type="button" value="取整(四舍五入)" onclick="alert(start)"/>

IE8下是“fileopen”囧

看来是命名冲突,BT的IE8
HTML code<inputtype="button" value="取整(四舍五入)" onclick="window.start(1)"></input>


原来如此
王集鹄 2010-02-12
  • 打赏
  • 举报
回复
<input type="button" value="取整(四舍五入)" onclick="alert(start)"/>

IE8下是“fileopen”囧

看来是命名冲突,BT的IE8
<input type="button" value="取整(四舍五入)" onclick="window.start(1)"></input>
shllove 2010-02-12
  • 打赏
  • 举报
回复
start 这个函数换个名字就可以了,估计是和什么关键字冲突了
语过添情 2010-02-12
  • 打赏
  • 举报
回复
引用 1 楼 shan1119 的回复:
from:functionstart(a)
to  :functionstarts(a)


非常感谢,我把start换成别的就可以用了。
start是javascript的保留字吗?为什么第一种情况可以呢?
shan1119 2010-02-12
  • 打赏
  • 举报
回复
from:function start(a)
to :function starts(a)

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧