时间:2021-07-01 10:21:17 帮助过:3人阅读
<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方式提交表单等