在项目中有一段js代码,但是不想修改原代码,自己另写了一个js代码文件,并想在调用手写代码的时候不调用原js代码!该怎样做呢!大神门帮帮忙啦!JavaScript

解决方案 »

  1.   

    贴个代码
    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function aa(){alert("bb");}
    function aa(){alert("aa");}

    </script>
    </head><body>
    <script type="text/javascript">
    aa();
    </script>
    </body>
    </html>
      

  2.   

    同名函数最后一个script标签起作用,所以你要哪个生效,script标签放最后或者在同一个script标签快中js代码放最后<script>
        function a() { alert(1) }
        function a() { alert(2) }
        function a() { alert(3) }
        function a() { alert(4) }    a()//4
    </script>
    <script>
        function a() { alert(3) }
    </script>
    <script>
        function a() { alert(2) }
    </script><script>
        function a() { alert(1) }
        a()//1
    </script>
      

  3.   

    不过这里推荐一个js的版本的管理工具。seajs。可以去看一看 。说不定是可以应用在你的项目中的