javascript实现网页字符定位的方法
本文实例讲述了javascript实现网页字符定位的方法。分享给大家供大家参考。具体如下:
这里实现输入要查询的字符串,点击定位后程序会自动跳到匹配的位置上
<html>
<formname="f1"action=""
onSubmit="if(this.t1.value!=null&&this.t1.value!='')
findString(this.t1.value);returnfalse">
<inputtype="text"name=t1value=""size=20>
<inputtype="submit"name=b1value="Find">
</form>
<p>
导读:11月2日,美国将举行中期选举,众议院国会议员将全部改选,参议院改选1/3,一些州也将进行州长选举。奥巴马能否令心怀不满的选民支持民主党,支撑民主党统治,尚不得而知
</p>
<scriptlanguage="JavaScript">
<!--
varTRange=null
functionfindString(str){
if(parseInt(navigator.appVersion)<4)return;
varstrFound;
if(window.find){
//CODEFORBROWSERSTHATSUPPORTwindow.find
strFound=self.find(str);
if(strFound&&self.getSelection&&!self.getSelection().anchorNode){
strFound=self.find(str)
}
if(!strFound){
strFound=self.find(str,0,1)
while(self.find(str,0,1))continue
}
}
elseif(navigator.appName.indexOf("Microsoft")!=-1){
//EXPLORER-SPECIFICCODE
if(TRange!=null){
TRange.collapse(false)
strFound=TRange.findText(str)
if(strFound)TRange.select()
}
if(TRange==null||strFound==0){
TRange=self.document.body.createTextRange()
strFound=TRange.findText(str)
if(strFound)TRange.select()
}
}
elseif(navigator.appName=="Opera"){
alert("Operabrowsersnotsupported,sorry...")
return;
}
if(!strFound)alert("String'"+str+"'notfound!")
return;
}
//-->
</script>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短