Chr*_*yes 1 javascript asp.net
我有一个输入框,我不希望有人按 Enter 键时发生回发
我希望 javascript 事件发生。
<input
type="text"
id="addressInput"
onkeydown="inputenter()"
autopostback="false"/>
function inputenter() {
if (event.keyCode == 13) {
seachLocations();
return false;
}
else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
就return false形式的JS函数,添加return false;在函数结束时。
或者<input type="text"
id="addressInput"
onkeydown ="return (event.keyCode!=13)"
autopostback="false"/>
更新:这个怎么样..?
<asp:TextBox ID="TextBox1" runat="server"
onkeydown="return CallEnterKeyFunc(event.keyCode);">
</asp:TextBox>
<script type="text/javascript">
function CallEnterKeyFunc(key) {
if (key == 13) { //for FF, i think you have to use evt.which
//enter key press
seachLocations();
return false;
}
else
return true;
}
function seachLocations() {
//your code
alert("hello");
}
</script>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10342 次 |
最近记录: |