js搜索框提示源码_搜索框代码html

hacker|
97

文章目录:

求一段JS代码,要求搜索当前页面,如果发现当前页面中有设定的字符,就给出提示

html

script

  function searchWords() {

    var words = document.getElementById('search').value;

    if (words != '') {

      var innerHTML = document.body.innerHTML;

      if (innerHTML.indexOf(words) != -1) {

        alert('找到了');

        if (words == '123') {

          alert('123不作操作');

        } else if (words == '456') {

          alert('456跳转页面');

          window.location.href = '';

        } else if (words == '567') {

          alert('567替换内容');

          document.body.innerHTML = innerHTML.replace(new RegExp(/(567)/g),'789');

        }

      }

    }

  }

/script

body

div123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/div

divinput id='search' type='text' placeholder='请输入查询字符' /button onclick='searchWords();'查询/button/div

/body

/html

JS 搜所提示框

!doctype htmlhtmlheadmeta charset="UTF-8"title百度搜索提示框/titlestyle* { margin: 0;padding: 0; outline: none;}.search101 { width: 650px; margin: 300px auto; font-size: 0;}.sou1 { width: 514px; height: 40px; color: #666; font: 16px Microsoft YaHei; border: 1px solid rgba(170,170,170,.9); border-right: 0; border-radius: 2px 0 0 2px; background: rgba(255,255,255,.9); padding: 0 30px 0 3px; vertical-align: top; display: inline-block; transition: .2s;}.sou2 { width: 100px; height: 42px; font: 16px Microsoft YaHei; color: rgba(255,255,255,.9); background: rgba(0,170,240,1); border: 0; border-left: 1px solid rgba(0,170,240,1); border-radius: 0 2px 2px 0; margin: 0 0 0 -1px; vertical-align: top; transition: .3s; display: inline-block; cursor: pointer;}.sou2:hover { background: rgba(0,140,220,.9);}.sou1:focus { color: #333; border: 1px solid rgba(0,170,240,1); border-right: none;}/style/headbody div class="06f3-4aed-c0af-48e4 search101" form action="" class="4aed-c0af-48e4-f318 search-form" method="" id="search-form" input id="ipt1" name="tn" type="hidden" value="baidu" input type="text" id="sou1" class="c0af-48e4-f318-011c sou1" name="word" maxlength="8048" value="" placeholder="" baiduSug=1 onmouseover="focus()" input type="submit" class="48e4-f318-011c-a8f5 sou2" value="百度一下" /form /div!-- 百度搜索提示 --script charset="gbk" src=""/script !-- we124.com/libs/js/opensug.js(无logo) --script document.getElementById("sou1").focus(); var txtObj = document.getElementById("alertSpan"); //回调函数,用于获取用户当前选择的文字 function show(str){ txtObj.innerHTML = str; } var params = { "XOffset": 0, //提示框位置横向偏移量,单位px "YOffset": 0, //提示框位置纵向偏移量,单位px "width": 204, //提示框宽度,单位px "fontColor": "#666", //提示框文字颜色 "fontColorHI": "#222", //提示框高亮选择时文字颜色 "fontSize": "16px", //文字大小 "fontFamily": "微软雅黑", //文字字体 "borderColor": "#d8d8d8", //提示框的边框颜色 "bgcolorHI": "#e8e8e8", //提示框高亮选择的颜色 "sugSubmit": true, //在选择提示词条是是否提交表单 }; BaiduSuggestion.bind("ipt1",params,show);/script/body/html

js搜索框代码

    /* 问题不够明确 */

    input class="5948-c135-acf0-d44d ipt_search" type="search" placeholder="请输入搜索内容"/

    script

        /* 搜索input */

        var searchIpt = document.getElementsByClassName('ipt_search')[0];

        /* 搜索内容 */

        var searchValue = searchIpt.value;

    /script

求搜索框的JS代码

这个简单点的方法来实现,应该就是DIV的display属性block和none的切换,并且点击你要的名称,关联的DIV中的内容随之改变就行了

应该很容易就能实现你要的

高分求js+php+ajax搜索自动提示代码

先声明一下,不要你的分,希望你问问题的时候客气一点,有时候回答问题的人只是为了帮忙。

其次,这种问题其实只是太平常,所以胡乱回答的太多。不过还是有比较精彩的例子的。

建议你到w3school.com.cn去学习一下js,ajax,css,都很简单。

有时间赚百度回答的积分的你,应该有时间来学习一下。里面关于ajax和php的例子是比较完美的。

既然不需要copy,就自己去找找吧!

如果三天时间,你没学会,再来问吧,同样免费回答你!

3条大神的评论

  • avatar
    访客 2022-07-04 上午 11:16:24

    议你到w3school.com.cn去学习一下js,ajax,css,都很简单。有时间赚百度回答的积分的你,应该有时间来学习一下。里面关于ajax和php的例子是比较完美的。既然不需要cop

  • avatar
    访客 2022-07-04 上午 12:20:09

    ,255,255,.9); padding: 0 30px 0 3px; vertical-align: top; display: inline-block; transition: .2s;}.sou2 { width: 100px; hei

  • avatar
    访客 2022-07-04 上午 08:42:42

    LMNOPQRSTUVWXYZ/divdivinput id='search' type='text' placeholder='请输入查询字符' /button onclick='searchWords();'查询/button/div/body/htmlJS 搜所提示框!doctype htm

发表评论