js文本框回车事件

js代码

$("#b-text").keypress(function(){
if(event.keyCode == 13){
var value=$("#b-text").val();
if(value.length > 0){
window.location="http://www.baidu.com/";
}else{
window.location="index.html";
}
}
});

html代码:

<input type="text" name="b-text" id="b-text" class="b-text"/>

原文地址:https://www.cnblogs.com/huhewei/p/12729163.html