henryli

以绑定click弹窗的方式,改为普通的链接,即 a[target=_blank],在点击打开新窗口之前,修改其href。

绑定mousedown,鼠标点击执行完成前修改href。

 

绑定focus,保证tab切换+enter时替换href。

 

<input type="search" id="keyword" value="" autocomplete="off" placeholder="请输入搜索关键字" />
        <a href="###" id="submit" target="_blank" >搜索</a>
        <script type="text/javascript">
                (function(document) {
                    var submit = document.getElementById(\'submit\');
                    var keyword = document.getElementById(\'keyword\');
                    var url = \'http://www.baidu.com/baidu?wd=\';
                    submit.onfocus = submit.onmousedown = function() {
                        var href = url + escape(keyword.value);
                        if (href !== submit.href) {
                            submit.href = url + escape(keyword.value)
                        }
                    } 

                })(document);
        </script>

 

ps:还可以在 在html代码中 以onclick  dom 0级方式绑定 、target方式提交表单等

分类:

技术点:

相关文章:

  • 2021-11-30
  • 2021-12-10
  • 2022-12-23
  • 2021-12-20
  • 2022-02-08
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
相关资源
相似解决方案