我想让我的功能可供用户使用,如果他们点击按钮,但如果他们也按下输入。下面是例子:如果我点击按钮Make function onClick和onKeypress JQuery/Javascript?
$('#searchBtn').on('click', function searchUser(){
$.ajax({
type: 'POST',
url: 'Components/Application.cfc?method=findUser',
data: {'searchFldVal':searchFldVal},
dataType: 'json'
}).done(function(obj){
return true;
}else{
return false;
}
});
return false;
}
}).fail(function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
});
}
});
<form name="searchForm" id="searchForm" action="#" method="POST" onsubmit="searchUser()">
\t <div>
\t \t <input type="text" name="searchFld" id="searchFld" size="24" maxlength="24" value="" title="Maximum size of the field is 24 characters." placeholder="Example: John, Miller" />
\t </div>
\t <div>
\t \t <input type="button" name="searchBtn" id="searchBtn" value="Search"/>
\t </div>
</form>
以上代码工作正常,但如果我输入几个字母,然后按进入我的页面将重新加载。该文件保存为.cfm
文件。我想在onClick
和onKeypress
上运行searchUser()
函数。如果有人知道如何实现这一点,请让我知道。
只是向上看,所提供的代码有错误。 –