如何在html中调用js函数

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片以渐显的方式自动播放</title>
<script language=javaScript>
<!--//
sandra0 = new Image();
sandra0.src = "/jscss/demoimg/wall_s1.jpg";
sandra1 = new Image();
sandra1.src = "/jscss/demoimg/wall_s2.jpg";
sandra2 = new Image();
sandra2.src = "/jscss/demoimg/wall_s3.jpg";
var i_strngth=1
var i_image=0
var imageurl = new Array()
imageurl[0] ="/jscss/demoimg/wall_s1.jpg"
imageurl[1] ="/jscss/demoimg/wall_s2.jpg"
imageurl[2] ="/jscss/demoimg/wall_s3.jpg"
function showimage() {
if(document.all) {
if (i_strngth <=110) {
testimage.innerHTML="<img style='filter:alpha(opacity="+i_strngth+")' src="+imageurl[i_image]+" border=0>";
i_strngth=i_strngth+10
var timer=setTimeout("showimage()",100)
}
else {
clearTimeout(timer)
var timer=setTimeout("hideimage()",1000)
}
}
if(document.layers) {
clearTimeout(timer)
document.testimage.document.write("<img src="+imageurl[i_image]+" border=0>")
document.close()
i_image++
if (i_image >= imageurl.length) {i_image=0}
var timer=setTimeout("showimage()",2000)
}
}
function hideimage() {
if (i_strngth >=-10) {
testimage.innerHTML="<img style='filter:alpha(opacity="+i_strngth+")' src="+imageurl[i_image]+" border=0>";
i_strngth=i_strngth-10
var timer=setTimeout("hideimage()",100)
}
else {
clearTimeout(timer)
i_image++
if (i_image >= imageurl.length) {i_image=0}
i_strngth=1
var timer=setTimeout("showimage()",500)
}
}
//-->
</script>
</head>
<body>
<div id="banner" style="position:absolute;visibility:visible;top:0px;left:0px">
图片要显示在这个div下,如何操作呀?
</div>
</body>
</html>
原文件是这样调用的
<body onLoad="showimage()">

不过我不想刚开始就调用,我要在后面的版块里面调用

一、工具:Dreamweaver软件、电脑

二、操作步骤:

【1】打开Dreamweaver软件,然后在创建新项目下选择HTML;

【2】点击“文件”选项,然后点击“另存为”,将文件命名为test,并将其保存在电脑桌面上;

【3】编写一个基本的html文件,该html文件包含一个用户名及一个密码输入文本框和一个确定以及一个取消按钮;

【4】在title标签下插入<script language="JavaScript">js代码</script>,然后在html中调用js函数;

【5】完成js代码编写及html调用js代码后保存tset.html文件,然后在浏览器中打开test.html文件,检查js代码执行的效果;

【6】在Dreamweaver软件中新建一个check.js文件(方法同html文件新建),在check文件中输入校验函数;

【7】然后在test.html的title标签下引用check.js文件;

【8】在程序中引用check.js文件中的js函数,然后在浏览器中刷新test.hmtl文件,然后在username的输入框中输入非法字符来检验js代码。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-11
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片以渐显的方式自动播放</title>
</head>
<body>
<div id="banner" style="position:absolute;visibility:visible;top:0px;left:0px">

<script language=javaScript>
<!--//
sandra0 = new Image();
sandra0.src = "/jscss/demoimg/wall_s1.jpg";
sandra1 = new Image();
sandra1.src = "/jscss/demoimg/wall_s2.jpg";
sandra2 = new Image();
sandra2.src = "/jscss/demoimg/wall_s3.jpg";
var i_strngth=1
var i_image=0
var imageurl = new Array()
imageurl[0] ="/jscss/demoimg/wall_s1.jpg"
imageurl[1] ="/jscss/demoimg/wall_s2.jpg"
imageurl[2] ="/jscss/demoimg/wall_s3.jpg"
function showimage() {
if(document.all) {
if (i_strngth <=110) {
testimage.innerHTML="<img style='filter:alpha(opacity="+i_strngth+")' src="+imageurl[i_image]+" border=0>";
i_strngth=i_strngth+10
var timer=setTimeout("showimage()",100)
}
else {
clearTimeout(timer)
var timer=setTimeout("hideimage()",1000)
}
}
if(document.layers) {
clearTimeout(timer)
document.testimage.document.write("<img src="+imageurl[i_image]+" border=0>")
document.close()
i_image++
if (i_image >= imageurl.length) {i_image=0}
var timer=setTimeout("showimage()",2000)
}
}
function hideimage() {
if (i_strngth >=-10) {
testimage.innerHTML="<img style='filter:alpha(opacity="+i_strngth+")' src="+imageurl[i_image]+" border=0>";
i_strngth=i_strngth-10
var timer=setTimeout("hideimage()",100)
}
else {
clearTimeout(timer)
i_image++
if (i_image >= imageurl.length) {i_image=0}
i_strngth=1
var timer=setTimeout("showimage()",500)
}
}
//-->
</script>

</div>
</body>
</html>追问

我加了好像没有反应

第2个回答  2011-03-11
<div>
<input type="button" value="call" onclick="showimage()">
</div>
这样是在div中放了一个按钮,点击的时候(onclick)调用你写的函数'showimage',不知道你要的是不是这样……追问

为什么没有反应呢?

追答

我也不太懂……
弱弱的问一下,原来那样写在就可以吗?
我也是初学,我自己复制过来,打开的时候说testimage未定义。

追问

是的,原来的是可以的。http://www.codefans.net/jscss/code/2299.shtml
我从这里复制来的

追答

你是不是把之前的div删掉了?

这样看看
额,刚刚input后面忘了斜杠

追问

没用,算了,就插一张图片算了……

本回答被提问者采纳