我有两个页面,a.html和b.html:
a.html<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script type="text/javascript" src="../js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="../js/prototype.js"></script>

<script type="text/javascript">
jQuery(function() {
new Ajax.Updater("mydiv", "b.html", {
method : "get",
evalScripts : true
});
});
</script>
</head>
<body>
<div id="mydiv"></div>
</body>
</html>
b.html<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script type="text/javascript">
function sayHello() {
alert("helloWorld!");
}
</script>
</head>
<body>
<input type="button" value="click me" onclick="sayHello();" />
</body>
</html>
单独访问b.html时,点击button,能够调用sayHello()函数。然而,访问a.html时,再点击button,JS错误,sayHello未定义。各位大侠,这个应该怎样解决啊?

解决方案 »

  1.   

    sayHello未定义
    说明页面找不到这个JS函数,
    你确认1下,
     <script type="text/javascript">
            jQuery(function() {
                new Ajax.Updater("mydiv", "b.html", {
                    method : "get",
                    evalScripts : true
                });
            });
            </script>
    这个语句是否执行了,然后你再alert(mydiv.innerHTML)
    看下,是什么问题
      

  2.   

    b.html中的sayHello()自定义函数有没有传给a.html
    页面中啊!
      

  3.   

    谢谢大家,我搞清楚原因了,b.html的函数应该这样定义:
    sayHello = function() {
        ...
    }