(js技巧)input文本框回车或者失去光标触发事件
问题1:
input文本框输入完成后回车,或者是失去光标时,触发事件。
实现方式
onchange="window.alert('触发事件,处理事情')" //失去光标时,触发事件并处理
onkeypress=" if(event.keyCode==13) { window.alert('触发事件,处理事情'); return false;}" //回车触发事件并处理
注: 在onkeypress事件中必须加入 return false;语句 主要避免input中的输入项丢失。
完整的例子:
<input type="text" id="inputGoodNo" style="width:197px;Height:31px;Font-Size:X-Large" onchange="... do some thing...." onkeypress=" if(event.keyCode==13) { ... do some thing....; return false;}"/>
input文本框输入完成后回车,或者是失去光标时,触发事件。
实现方式
onchange="window.alert('触发事件,处理事情')" //失去光标时,触发事件并处理
onkeypress=" if(event.keyCode==13) { window.alert('触发事件,处理事情'); return false;}" //回车触发事件并处理
注: 在onkeypress事件中必须加入 return false;语句 主要避免input中的输入项丢失。
完整的例子:
<input type="text" id="inputGoodNo" style="width:197px;Height:31px;Font-Size:X-Large" onchange="... do some thing...." onkeypress=" if(event.keyCode==13) { ... do some thing....; return false;}"/>
posted on 2011-01-05 11:05 狗尾草-大数据收割基 阅读(15583) 评论(0) 收藏 举报