从另一个JS返回Html里面的Javascript值

0 html javascript nested function

我需要你的帮助我知道这是一个愚蠢的问题,但我无法解决它... sorrry :(

我有一个javascript文件welcome.js

    function alert()
    {
    return 10;
    } 
Run Code Online (Sandbox Code Playgroud)

我有另一个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">
Run Code Online (Sandbox Code Playgroud)

我继续在mozilla控制台中收到此错误

时间戳:2013年5月28日下午9:56:47错误:NS_ERROR_XPC_NOT_ENOUGH_ARGS:参数不足[nsIDOMWindow.alert]

Nik*_*las 5

您的javascript(welcome.js)未加载到脚本标记中的语法错误.你错过了"报价text/javascript.

alert();正在呼叫window.alert()它需要一个参数在Firefox被传递(例如不在Chrome).由于您自己的welcome.js永远不会被加载(由于语法错误),它永远不会重写全局alert()函数.