我有一个带有两个提交按钮的页面,该页面还打开一个具有另一个提交按钮的弹出窗口(id:addPopup)。每当在弹出窗口上按 Enter 时,都会触发登陆页面上的第一个提交按钮,但我想改为调用弹出窗口上的按钮。 这是弹出窗口中“提交”按钮的代码:
<a4j:commandButton id="continueButton" styleClass="btn btn-primary"
value="Continue"
action="#{optionsController.continue()}"
render="menuPanel addSection addOptionsPanel"
oncomplete="if(#{empty facesContext.messageList})#{rich:component('addPopup')}.hide();"
disabled="#{empty optionsController.addParcelId and empty optionsController.addGridReference}" />
我尝试过使用 richfaces 热键,但它不起作用并且页面被提交
<rich:hotKey selector="#addPopup" enabledInInput="true" key="return" preventDefault="true"/>
也尝试过使用
<script type="text/javascript">
$(document).bind('keydown', 'Return', function(e){
key = e.keyCode;
if(key == 13){
var continueBtn = document.getElementById('continueButton'));
continueBtn.click();
}
});
但这也不起作用。关于我做错了什么或任何其他可能有效的方法有什么建议吗?
最佳答案
我设法使用此脚本处理回车键:
<script type="text/javascript">
$(document).bind('keydown', 'Return', function(e){
key = e.keyCode;
if(key == 13){ // Enter key pressed
// Get button binding from backing bean.
var continueBtn = document.getElementById("#{optionsController.continueButton.clientId}");
if(!continueBtn.disabled){
continueBtn.click();
}
return false;
}
});
还在支持 bean 中添加了 continueButton 的绑定(bind),以及 getter 和 setter
关于javascript - 当在弹出窗口中按 Enter 时,会触发登陆页面上的提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28383579/