php js 搜索框设置回车触发搜索 按回车没反应
问题描述:
请问问题出在哪里?
答
主要是e.keyCode 中k要小写
完善一下代码
<input type="text" id="search" value="" onkeydown="search(arguments[0])" />
<script type="text/javascript">
function search(e) {
var e = e||window.event;
if (e.keyCode==13) {
var val = document.getElementById("search").value;
alert(val);
window.location.href = "https://www.baidu.com/s?wd="+encodeURIComponent(val);
}
}
</script>
答
e.keyCode 中k是小写