test1.js
<script type="text/javascript">
function hello()
{
alert("hello!!!!!");
}
</script> test2.js
<script src="webfun.js">
hello();
</script> 写错了吧
<script type="text/javascript">
function hello()
{
alert("hello!!!!!");
}
</script> test2.js
<script src="webfun.js">
hello();
</script> 写错了吧
在HTML文件中使用 <script src="...">直接包含,
JS文件内部不用声明script.
直接调用就以了。你可以这样考虑,
你把HTML语句和JS语句分别放在了不同的文件里面.
在画面装载的时候,
浏览器根据指明的文件位置,
把他们拼接到一起形成一个大文件.
就这么回事儿.
<script type="text/javascript">
function hello(item)
{
alert("test1.js hello!!!!!"+item);
}
</script> test2.js
<script type="text/javascript" src="test1.js"></script>
<script type="text/javascript">
hello(item) ;
</script> test.html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="js/test2.js" type="text/javascript"> </script>
</head>
<body>
<input type="submit" onclick="hello()" name="sub"/>
</body>
</html>
function hello()
{
alert("test1.js hello!!!!!");
} test2.js
function hello2()
{
hello() ;
}test.html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script src="js/test2.js" type="text/javascript"> </script>
<script type="text/javascript" src="test1.js"> </script>
</head>
<body>
<input type="submit" onclick="hello2()" name="sub"/>
</body>
</html>
test1.js
function hello()
{
alert("hello!!!!!");
} test2.js
hello(); test.html
<!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=gb2312" />
<title>无标题文档 </title>
<script src="js/test1.js" type="text/javascript"/>
<script src="js/test2.js" type="text/javascript"/>
</head> <body>
<input type="submit" onclick="hello()" name="sub"/>
</body>
</html>
<script src="js/test1.js" type="text/javascript"></script>
<script src="js/test2.js" type="text/javascript"></script>
或者等待事件触发来执行
跟绕口令似的
<script src="js/test1.js" type="text/javascript"> </script>
<script src="js/test2.js" type="text/javascript"> </script>
汗!- -
看来还是mm受欢迎啊,大家太热情了,O(∩_∩)O哈哈~