我正在调用页面刷新后选择组件 ID 的函数:
$(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 对我来说还不够)。可能吗?
更新(部分功能解决方案):
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>在调用函数后呈现表单,因此选择和焦点被清除:(