本帖最后由 tc_yf 于 2012-06-16 11:05:14 编辑

解决方案 »

  1.   

    函数正常调用了啊  问题是 var oHide = document.getElementById(idTokHide);没这个对应的对象啊
      

  2.   

    那个定义了。我写了一个简单的代码来表现这个问题
    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript">
    function myFunction()
    {
    alert("Hello World!");
    }
    </script>
    </head>
    <body>
    <script type="text/javascript">
    document.write('<button onclick="return myFunciton();"> Click Me');
    document.write('</button>');
    </script>
    <p>By clicking the button above, a function will be called. The function will alert a message.</p>
    </body>
    </html>
    这个运行的话点击没有用,也是现实函数未定义。求教啊,是不是不能用document.write来写啊?
      

  3.   

    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript">
    function myFunction()
    {
    alert("Hello World!");
    }
    </script>
    </head>
    <body>
    <script type="text/javascript">
    document.write('<button onclick="myFunction()"> Click Me');
    document.write('</button>');
    </script>
    <p>By clicking the button above, a function will be called. The function will alert a message.</p>
    </body>
    </html>
    这样就可以弹出来了
      

  4.   

    谢谢您的回答,我仔细看了一下代码,我举得例子不太合适,我举得例子只是因为函数名写错了,
    我重新写了一个例子,我觉得是因为window.onload函数的原因,但是不知道怎么解决,代码如下:<!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript">
    //在这里单独添加也不行
    function myFunction(i)
    {
    alert("Hello World!");
    }
    </script>
    </head>
    <body>
    <script type="text/javascript">
    window.onload = function() 

    //我在这里单独添加过,也不行
    function myFunction(i)
    {
    alert("Hello World!");
    }
    var tcount=1;
    document.write('<a href ="#" onclick="myFunction(tcount)"> Click Me');
    document.write('</a>');
    }
    </script>
    <p>By clicking the button above, a function will be called. The function will alert a message.</p>
    </body>
    </html>
    谢谢了!
      

  5.   

    如果你把函数写在onload事件里,那它只会在onload的时候定义或者执行一次,再去ONCLICK肯定没有了。
      

  6.   

    楼主我怎么说你呢,你在onload里面写
    document.write('<a href ="#" onclick="myFunction(tcount)"> Click Me');
    document.write('</a>');
    这2句代码你明白什么意思吗?
    不明白你可以右键查看页面源代码你会发现页面上就剩这一句了
    <a href ="#" onclick="myFunction(tcount)"> Click Me</a>
      

  7.   

    还有你函数传参myFunction(tcount)你觉得这样能传过去?建议你先学学javascript 基本语法
    //在这里单独添加也不行
        function myFunction() {    alert("Hello World!");
    }
    还有你的这个函数不行上面我也说了你一个document.write把整个页面重写了,要想函数能执行也得把函数写进去,把你的给你改了下你试试
    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <script type="text/javascript">
    //在这里单独添加也不行
        function myFunction() {    alert("Hello World!");
    }
    </script>
    </head>
    <body>
    <script type="text/javascript">
        window.onload = function () {
            var tcount = 10000;
            document.write("<script type=\"text/javascript\">function myFunction(i){ alert(i);}<\/script>");
            document.write('<a href ="#" onclick="myFunction('+tcount+')"> Click Me');
            document.write('</a>');
        }
    </script></body>
    </html>