BrJfUsTD
V2EX  ›  问与答

JavaScript 搜索页面里的关键字

  •  
  •   BrJfUsTD · Sep 17, 2022 · 1891 views
    This topic created in 1361 days ago, the information mentioned may be changed or developed.

    想在页面里加个搜索框,效果类似浏览器自带的那个搜索,输入关键字查找页面里的匹配字符。

    请问这种有简单的 JavaScript 功能可以用吗?

    有没有可能直接调用浏览器的搜索(但搜索框指定在页面的自定义位置)?

    7 replies    2022-09-17 17:32:58 +08:00
    Danswerme
        1
    Danswerme  
       Sep 17, 2022   ❤️ 1
    既然“效果类似浏览器自带的那个搜索”,那为什么不用浏览器自带的搜索呢?
    keepeye
        2
    keepeye  
       Sep 17, 2022
    搜索到指定的 dom ,然后调用 el.getBoundingClientRect()获取位置,我 google 的
    BrJfUsTD
        3
    BrJfUsTD  
    OP
       Sep 17, 2022
    @Danswerme 主要为方便访客使用,有些人不知道可以用浏览器搜索
    BrJfUsTD
        4
    BrJfUsTD  
    OP
       Sep 17, 2022
    @keepeye 谢谢!我去了解看看。
    f0rger
        5
    f0rger  
       Sep 17, 2022 via iPhone
    直接 alert(‘按 Ctrl+F 搜索页面内容’)
    BrJfUsTD
        7
    BrJfUsTD  
    OP
       Sep 17, 2022
    @iNaru 谢谢!我去看看。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1041 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 18:47 · PVG 02:47 · LAX 11:47 · JFK 14:47
    ♥ Do have faith in what you're doing.