我需要你的帮助我知道这是一个愚蠢的问题,但我无法解决它... ...谢谢:(
我有一个javascript文件welcome.js 因为我有
function alert()
{
return 10;
}
我有另一个html文件welcome.html,其中调用了welcome.js文件
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript src="welcome.js"></script>
<script>
function myFunction()
{
var x = alert();
return x;
}
</script>
</head>
<body>
<input type="button" onclick="myFunction();" value="Show alert box">
我继续在mozilla控制台中收到此错误
时间戳:2013年5月28日下午9:56:47 错误:NS_ERROR_XPC_NOT_ENOUGH_ARGS:参数不足[nsIDOMWindow.alert]
答案 0 :(得分:5)
您的javascript(welcome.js)未加载到脚本标记中的语法错误。您在"
之后错过了text/javascript
引用。
alert();
正在调用window.alert()
,这需要在Firefox中传递参数(例如在Chrome中不会)。由于您自己的welcome.js永远不会被加载(由于语法错误),它永远不会重写全局alert()函数。
答案 1 :(得分:3)
警告功能名称不应该被覆盖,因为在这种情况下,如果你使用
alert(something)
您将调用新功能而不是对话功能
您有两个选择:
window.alert(something)
来区分答案 2 :(得分:0)
您无法覆盖window.alert()
功能,请尝试以下操作:
function test()
{
return 10;
}
然后在你的HTML中使用test()
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript src="welcome.js"></script>
<script>
function myFunction()
{
var x = test();
return x;
}
</script>
</head>
<body>
<input type="button" onclick="myFunction();" value="Show alert box">