<title>hello</title>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/custom.js"></script>
<script type="text/javascript" src="js/tablecloth.js"></script>
<link rel="stylesheet" href="style/default.css" />
<link rel="stylesheet" href="style/custom.css" />
<link rel="stylesheet" href="style/tablecloth.css" />
</head><body onload="ready(); test(); tablecloth(); " >上面是我的html页面的代码,在代码里我引入了2个js文件,然后在body的onload里写了3个函数,其中ready(); test(); 是属于custom.js的, tablecloth()是属于tablecloth.js的。
函数的具体代码我就不贴了, 因为我觉得跟代码应该没有太大关系。   在tablecloth()函数里,我对table增加一些效果,比如onmousemove之类的,就是鼠标移上去会有底色;
   在test();函数里,我用jqeury在原有的table上动态插入了一些行和列。

下面说说问题:
   页面打开后,表格的行和列插入进去了,但是tablecloth()里的效果没有出来,好像没有执行一样,然后我在test(); 函数,也就是动态插入行列的最后面加一个alert("ok"),这样再运行会弹出一个窗口,把窗口点掉后效果就出来了,也就是说此时tablecloth()执行了。这个是什么原因呢?是不是跟执行顺序有关,我要怎么解决这个问题呢?

解决方案 »

  1.   

    把你要运行的写到一个函数里吧
    function all(){
    ready(); 
    test(); 
    tablecloth();
    }
    <body onload="all()" >
      

  2.   


    <script type="text/javascript">
    jQuery(document).ready(function()
    {
    ready();
      test(); 
      tablecloth();


    })
    </script>你的问题应该是没监听到事件
      

  3.   

    就onload函数里面调用不同js里面的方法啊
      

  4.   

    你的意思是onload里调用all()对吗?那all应该写在哪呢?如果all写在其中一个js里
    那all里面能直接调用另外一个js文件里的函数么?
      

  5.   

    <title>hello</title>
    <script type="text/javascript" src="js/jquery-1.3.2.min.js">
    </script><script type="text/javascript" src="js/custom.js">
    </script><script type="text/javascript" src="js/tablecloth.js"></script>
    <link rel="stylesheet" href="style/default.css" />
    <link rel="stylesheet" href="style/custom.css" />
    <link rel="stylesheet" href="style/tablecloth.css" />
    <script>
    $(function(){
        ready(); 
        test(); 
        tablecloth(); 
    });
    </script>
    </head> 
    <body>