CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  HTML(CSS)

可以实现HTML页面的本页查询吗?好像CONTROL+F一样

楼主No001(Zidane5)(Beckham7)2005-06-29 12:39:43 在 Web 开发 / HTML(CSS) 提问

可以实现HTML页面的本页查询吗?好像CONTROL+F一样  
   
  我想把搜索框做到页面上面  
   
   
  请指教! 问题点数:20、回复次数:5Top

1 楼slayerbb(名字被抢了)回复于 2005-06-29 17:02:36 得分 0

can   but   so   complex..  
  Top

2 楼白夜花寒(远藤花已谢,白夜花未寒)回复于 2005-06-30 06:27:16 得分 0

instr   vbs  
  js   match用正则Top

3 楼lanyd(寻找甘当科学家的女人)回复于 2005-06-30 10:04:28 得分 0

需要吗?  
   
  你不会直接调用IE的ctrl+f啊...Top

4 楼MyGhosts(阿辉)回复于 2005-07-01 23:40:41 得分 10

全文搜索代码,仅供参考,代码转自本坛:  
   
  <script     language="JavaScript">      
  var     NS4     =     (document.layers);      
  var     IE4     =     (document.all);      
  var     win     =     window;                      
  var     n             =     0;      
  function     findInPage(str)     {      
        var     txt,     i,     found;      
        if     (str     ==     "")      
                return     false;      
        if     (NS4)     {      
                if     (!win.find(str))      
                        while(win.find(str,     false,     true))      
                                n++;      
                else      
                        n++;      
                if     (n     ==     0)      
                        alert("没有找到。");      
        }      
        if     (IE4)     {      
                txt     =     win.document.body.createTextRange();      
                        for     (i     =     0;     i     <=     n     &&     (found     =     txt.findText(str))     !=     false;     i++)     {      
                        txt.moveStart("character",     1);      
                        txt.moveEnd("textedit");      
                }      
                if     (found)     {      
                        txt.moveStart("character",     -1);      
                        txt.findText(str);      
                        txt.select();      
                        txt.scrollIntoView();      
                        n++;      
                }      
                else     {      
                        if     (n     >     0)     {      
                                n     =     0;      
                                findInPage(str);      
                        }      
                        else      
                                alert("没有找到。");      
                }      
        }      
        return     false;      
  }      
  </script>      
  <form     name="search"     onSubmit="return     findInPage(this.string.value);">      
  <font     size=3><input     name="string"     type="text"     size=15     onChange="n     =     0;"></font>      
  <input     type="submit"     value="搜索">         查找页面关键字      
  </form>Top

5 楼yourlunch(健能)回复于 2005-07-02 17:57:47 得分 10

以前都遇过这问题,呵..帮你解决吧  
  ---------------------------------------------------------------      
     
  <object     id=saOC     CLASSID=''clsid:B45FF030-4447-11D2-85DE-00C04FA35C89''     HEIGHT=0     width=0></object>      
  <input     type=button     value=搜索     onclick="saOC.NavigateToDefaultSearch()">      
  ---------------------------------------------------------------      
     
  <script     language="Javascript">      
  var     NS4     =     (document.layers);                 //     Which     browser?      
  var     IE4     =     (document.all);      
  var     win     =     window;                 //     window     to     search.      
  var     n             =     0;      
  function     findInPage(str)     {      
        var     txt,     i,     found;      
        if     (str     ==     "")      
                return     false;      
        //     Find     next     occurance     of     the     given     string     on     the     page,     wrap     around     to     the      
        //     start     of     the     page     if     necessary.      
        if     (NS4)     {      
                //     Look     for     match     starting     at     the     current     point.     If     not     found,     rewind      
                //     back     to     the     first     match.      
                if     (!win.find(str))      
                        while(win.find(str,     false,     true))      
                                n++;      
                else      
                        n++;      
                //     If     not     found     in     either     direction,     give     message.      
                if     (n     ==     0)      
                        alert("Not     found.");      
        }      
        if     (IE4)     {      
                txt     =     win.document.body.createTextRange();      
                //     Find     the     nth     match     from     the     top     of     the     page.      
                for     (i     =     0;     i     <=     n     &&     (found     =     txt.findText(str))     !=     false;     i++)     {      
                        txt.moveStart("character",     1);      
                        txt.moveEnd("textedit");      
                }      
                //     If     found,     mark     it     and     scroll     it     into     view.      
                if     (found)     {      
                        txt.moveStart("character",     -1);      
                        txt.findText(str);      
                        txt.select();      
                        txt.scrollIntoView();      
                        n++;      
                }      
                //     Otherwise,     start     over     at     the     top     of     the     page     and     find     first     match.      
                else     {      
                        if     (n     >     0)     {      
                                n     =     0;      
                                findInPage(str);      
                        }      
                        //     Not     found     anywhere,     give     message.      
                        else      
                                alert("Not     found.");      
                }      
        }      
        return     false;      
  }      
  </script>      
  <form     name="search"     onSubmit="return     findInPage(this.string.value);">      
  <font     size=3><input     name="string"     type="text"     size=15     onChange="n     =     0;"></font>      
  <input     type="submit"     value="查找">      
  </form>Top

相关问题

  • 如何获取本页的Html代码?
  • f
  • f
  • ATL写HTML Control!
  • 在本页的服务器button的click事件中如何取得HTML控件的值?
  • 关于html control和web control?
  • 我在html页面怎样嵌入一段javascript代码,把本页面的源文件读出来显示在一个text里面
  • 如何刷新本页面?
  • 怎么在本页面强制刷新本页?
  • san f

关键词

  • 页面

得分解答快速导航

  • 帖主:No001
  • MyGhosts
  • yourlunch

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo