日期:2014-05-16  浏览次数:20309 次

按下Enter回车后触发你想要的js方法【原创】

按我的需求,我是想被提交的input里面的值可以得到js的验证判断和sumbit提交,所以我在这个input标签的里面放了如下代码:

onkeypress="if (event.keyCode==13){save();return false;也就是:

<input id="operationNumber" class="input" type="text" value="" onkeypress="if (event.keyCode==13){save();return false;}"?? style="width:200px" />

ok,这样就就可以光标在这个input的时候回车出发save方法。而一般的按钮事件很简答。如下:

<input type="image" src="${sessionScope._contextPath}/images/${sessionScope.imagedir}/button_save.gif" width="78" height="28" onclick="save();return false;"
???? style="cursor: pointer;"/>

?

就是用onclick属性。ok~

?