日期:2014-05-16  浏览次数:20373 次

document.getElementById在IE中运行报错
本帖最后由 jamseyang 于 2011-01-24 14:26:17 编辑
以下代码在FireFox、Chrome中运行OK,但在IE中报错

<html>
<head><title>Simple Add Function</title>
<script language="javascript">
function AddFun()
{
num1 = document.getElementById("num1").value;
num2 = document.getElementById("num2").value;
sum =parseFloat(num1)+parseFloat(num2);
alert(sum);
}
</script>
</head>
<body>
<input name="num1" id="num1" type="text" value=""/>
+
<input name="num2" id="num2" type="text" value=""/>
<input name="equals" type="button" value=" = " onclick="AddFun()">
</body>
</html>

------解决方案--------------------
<html>
    <head><title>Simple Add Function</title>
        <script language="javascript">
            function AddFun()
            {            
var num1, num2, sum;
                num1 = document.getElementById("num1").value;
                num2 = document.getElementById("num2").value;  
                sum =parseFloat(num1)+parseFloat(num2);
                alert(sum);
            }
        </script>    
    </head>
    <body>        
        <input name="num1" id="num1" type="text" value=""/>