资料
表格
制度
合同
管理
职场
经营
创业
范文
总结
计划
作文
文章
美文
词句
教程
模板
图片
字体
图标
办公
人事
财务
生产
管理资源吧首页
>>>
教程
>>>
编程
>>>
JavaScript教程
>>>
Js 打字效果 逐一出现的文字
第一种:打印多个文字
<title>逐个出现的文字</title> <img src="/_New/_cj/myeditor/sysimage/space.gif" class="ewebeditor__script" _ewebeditor_fake_tag="script" _ewebeditor_fake_value="%3Cscript%20language%3Djavascript%3E%20%0D%0Avar%20layers%20%3Ddocument.layers%2Cstyle%3Ddocument.all%2Cboth%3Dlayers%7C%7Cstyle%2Cidme%3D908601%3B%20%0D%0Aif(layers)%7BlayerRef%3D'document.layers'%3BstyleRef%20%3D''%3B%7Dif(style)%7BlayerRef%3D'document.all'%3BstyleRef%20%3D%20%0D%0A'.style'%3B%7D%20%0D%0Afunction%20writeOnText(obj%2Cstr)%7B%20%0D%0Aif(layers)with(document%5Bobj%5D)%7B%20document.open()%3Bdocument.write(str)%3Bdocument.close()%3B%7D%20%0D%0Aif(style)eval(obj%2B'.innerHTML%3Dstr')%3B%20%7D%20%0D%0Avar%20dispStr%3Dnew%20Array(%22%E8%84%9A%E6%9C%AC%E4%B9%8B%E5%AE%B6%E6%98%AF%E4%B8%80%E4%B8%AA%E4%B8%93%E4%B8%9A%E7%9A%84%E6%94%B6%E9%9B%86%E5%90%84%E7%B1%BB%E8%84%9A%E6%9C%AC%E5%AD%A6%E4%B9%A0%E8%B5%84%E6%96%99%E7%9A%84%E7%BD%91%E7%AB%99%2C%E5%B0%BD%E9%87%8F%E4%BF%AE%E6%AD%A3%E9%94%99%E8%AF%AF%E6%89%93%E9%80%A0%E7%B2%BE%E5%93%81%E8%84%9A%E6%9C%AC%E7%B1%BB%E5%AD%A6%E4%B9%A0%E7%BD%91%E7%AB%99%2C%E6%88%91%E4%BB%AC%E4%B8%BA%E5%A4%A7%E5%AE%B6%E6%B8%B8%E6%88%8F%E8%84%9A%E6%9C%AC%E8%B5%84%E6%BA%90%2C%E6%BA%90%E7%A0%81%2C%E8%BD%AF%E4%BB%B6%2Casp%2Cphp%2Cjavascript%E7%AD%89%E7%BC%96%E7%A8%8B%E8%B5%84%E6%96%99%2C%E6%98%AF%E7%BD%91%E9%A1%B5%E5%88%B6%E4%BD%9C%2C%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%2C%E7%BD%91%E7%AB%99%E5%BB%BA%E8%AE%BE%E4%BA%BA%E5%A3%AB%E7%9A%84%E8%81%9A%E9%9B%86%E5%9C%BA%E6%89%80%E3%80%82%22)%3B%20%0D%0Avar%20overMe%3D0%3B%20%0D%0Afunction%20txtTyper(str%2Cidx%2CidObj%2CspObj%2Cclr1%2Cclr2%2Cdelay%2Cplysnd)%7B%20%0D%0Avar%20tmp0%3Dtmp1%3D%20''%2Cskip%3D100%3B%20%0D%0Aif%20(both%20%26%26%20idx%3C%3Dstr.length)%20%7B%20%0D%0Aif%20(str.charAt(idx)%3D%3D'%3C')%7B%20while(str.charAt(idx)!%3D'%3E')%20idx%2B%2B%3Bidx%2B%2B%3B%7D%20%0D%0Aif%20(str.charAt(idx)%3D%3D'%26'%20%26%26%20str.charAt(idx%2B1)!%3D'%20')%7B%20while%20(str.charAt(idx)!%3D%20'%3B')idx%2B%2B%3Bidx%2B%2B%3B%7D%20%0D%0Atmp0%20%3D%20str.slice(0%2Cidx)%3B%20%0D%0Atmp1%20%3D%20str.charAt(idx%2B%2B)%3B%20%0D%0Aif%20(overMe%3D%3D0%20%26%26%20plysnd%3D%3D1)%7B%20%0D%0Aif%20(navigator.plugins%5B0%5D)%7B%20%0D%0Aif(navigator.plugins%5B%22LiveAudio%22%5D%5B0%5D.type%3D%3D%22audio%2Fbasic%22%20%26%26%20navigator.javaEnabled())%7Bdocument.embeds%20%0D%0A%5B0%5D.stop()%3B%20%0D%0AsetTimeout(%22document.embeds%5B0%5D.play(false)%22%2C100)%3B%7D%20%0D%0A%7D%20else%20if%20(document.all)%7B%20%0D%0Ading.Stop()%3B%20%0D%0AsetTimeout(%22ding.Run()%22%2C100)%3B%7D%20%0D%0AoverMe%3D1%3B%7Delse%20overMe%3D0%3B%20%0D%0AwriteOnText(idObj%2C%20%22%3Cspan%20class%3D%22%2BspObj%2B%22%3E%3Cfont%20color%3D'%22%2Bclr1%2B%22'%3E%22%2Btmp0%2B%22%3C%2Ffont%3E%3Cfont%20color%3D'%22%2Bclr2%20%0D%0A%2B%22'%3E%22%2Btmp1%2B%22%3C%2Ffont%3E%3C%2Fspan%3E%22)%3B%20%0D%0AsetTimeout(%22txtTyper('%22%2Bstr%2B%22'%2C%20%22%2Bidx%2B%22%2C%20'%22%2BidObj%2B%22'%2C%20'%22%2BspObj%2B%22'%2C%20'%22%2Bclr1%2B%22'%2C%20'%22%2Bclr2%2B%22'%2C%20%22%2Bdelay%2B%22%20%2C%22%2Bplysnd%2B%22)%22%2Cdelay)%3B%7D%7D%20%0D%0Afunction%20init()%7BtxtTyper(dispStr%5B0%5D%2C%200%2C%20'ttl0'%2C%20'ttl1'%2C%20'red'%2C%20'%2399FF33'%2C%20300%2C%200)%3B%7D%20%0D%0A%3C%2Fscript%3E"> <DIV class=ttl1 id=ttl0></DIV> <body onload=init()>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行
]
第二种:在textarea中显示的效果
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>打字效果</title> <img src="/_New/_cj/myeditor/sysimage/space.gif" class="ewebeditor__script" _ewebeditor_fake_tag="script" _ewebeditor_fake_value="%3Cscript%20language%3D%22javascript%22%20type%3D%22text%2Fjavascript%22%3E%20%0D%0A%3C!--%20%0D%0Avar%20max%3D0%3B%20%0D%0Afunction%20keeptext()%20%0D%0A%7B%20%0D%0Amax%3Dkeeptext.arguments.length%3B%20%0D%0Afor(var%20i%3D0%3Bi%3C%3Dmax%3Bi%2B%2B)%20%0D%0Athis%5Bi%5D%3Dkeeptext.arguments%5Bi%5D%3B%20%0D%0A%7D%20%0D%0Amytext%3Dnew%20keeptext(%22%E8%84%9A%E6%9C%AC%E4%B9%8B%E5%AE%B6%E6%B5%8B%E8%AF%95%E4%BB%A3%E7%A0%81%22)%3B%20%0D%0Avar%20x%3D0%2Cpos%3D0%3B%20%0D%0Avar%20len%3Dmytext%5B0%5D.length%3B%20%0D%0Afunction%20typetext()%20%0D%0A%7B%20var%20mytt%3Ddocument.getElementById(%22typefield%22)%3B%20%0D%0Amytt.value%3Dmytext%5Bx%5D.substring(0%2Cpos)%2B%22_%22%3B%20%0D%0Aif(pos%2B%2B%3D%3D1)%20%0D%0A%7B%20%0D%0AsetTimeout(%22typetext()%22%2C2000)%3B%20%0D%0Aif(%2B%2Bx%3D%3Dmax)%20x%3D0%3B%20%0D%0Alen%3Dmytext%5Bx%5D.length%3B%20%0D%0A%7D%20%0D%0Aelse%20%0D%0AsetTimeout(%22typetext()%22%2C300)%3B%20%0D%0A%7D%20%0D%0A--%3E%20%0D%0A%3C%2Fscript%3E"> </head> <body onload="typetext()"> <form name="typeform" runat="server"> <div> <center><h1>打字效果</h1><br> <hr /> <textarea id="typefield" cols="20" rows="20"></textarea> </center> </div> </form> </body> </html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行
]
教程首页
更多教程