我不确定为什么这不起作用?我尝试了几种方法并环顾四周,但这些例子都不适用于我。我的代码:
HTML
<div id='SearchBar'>
<form id='SearchBar'>
<input placeholder='Search' id='SearchBar'></input>
</form>
</div>
CSS
#SearchBar{
background:#ffffff;
width:224px;
height:32px;
float:right;
}
form#SearchBar {
width:100%;
height:100%;
}
input#SearchBar {
font-size:16px;
border:none;
width:208px;
height:32px;
padding:0 8px;
}
input#SearchBar:focus{
outline-color:#2c5aa0;
}
的jQuery
$('input#SearchBar').keypress(function(event) {
if (event.which == 13) {
window.location = list.html; //or submit or do whatever
}
});
感谢任何帮助。我哪里错了?
答案 0 :(得分:0)
收听keyup
事件,您遗漏了list.html
的引号,list
对象为undefined
,因此它没有html
属性!< / p>
$(function(){
$('#SearchBar').keyup(function(event) {
if (event.which == 13) {
window.location.href = 'list.html';
}
});
})