源代码:
//--------------------------------------------------------------<!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()函数呢?
//--------------------------------------------------------------<!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()函数呢?
to :function starts(a)
非常感谢,我把start换成别的就可以用了。
start是javascript的保留字吗?为什么第一种情况可以呢?
<input type="button" value="取整(四舍五入)" onclick="window.start(1)"></input>