每个提交按钮调用相同的功能 [英] Each submit button calls the same function
问题描述
我正在调用用于在页面刷新后选择组件ID的函数:
I'm calling function for selecting component ID after page refresh:
$(document).ready(
function() {
document.getElementById('form:#{myBDE.componentId}').focus();
document.getElementById('form:#{myBDE.componentId}').select();
}
)
我的提交按钮示例:
<h:form id="form">
<h:commandButton id="btnSubmit" action="#{myBDE.save}" type="submit" >
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
...
</form>
我如何创建每次单击任何提交按钮时都将调用的相同函数(我使用的是Ajax,所以我在不重新加载页面的情况下工作,document.ready对我来说还不够).有可能吗?
How can I create the same function to be called each time I click any submit button (I'm using ajax, so I'm working without page reloading, document.ready is not enough for me). Is it possible?
更新(部分功能解决方案):
update (partially functional solution):
var myFunc = function() {
document.getElementById('form:#{myBDE.componentId}').focus();
document.getElementById('form:#{myBDE.componentId}').select();
};
$(document).ready(function() {
myFunc();
$('input[type=submit]').click(myFunc);
});
我可以调用将onclick="return myFunc();"
添加到h:commandButton
的函数,问题是<f:ajax>
在调用该函数后呈现表单,因此清除了选择和焦点:(
I can call the function adding onclick="return myFunc();"
to h:commandButton
, problem is, that <f:ajax>
render the form after calling the function, so the select and focus is cleared :(
推荐答案
这应该有效
$('input[type="submit"]').click(function(){
document.getElementById('form:#{myBDE.componentId}').focus();
document.getElementById('form:#{myBDE.componentId}').select();
});
实际上,您可以将函数绑定到任何事件.在这种情况下,这是属性为type = submit
In fact you can bind a function to any events. In this case it is the click event for the input tag with the attribute type=submit
这篇关于每个提交按钮调用相同的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!