无法通过JavaScript单击隐藏的按钮 [英] Cannot click hidden button by JavaScript
问题描述
function openEditDialog(){
window.showModalDialog('/atmew/pages/asset/searchInclude/assetEdit.mew');
document.getElementById('reData').click();
alert('after rerender');
}
然后有一个按钮:
<a4j:commandLink id="edit" action="#{searchController.openAssetEdit}"
oncomplete="openEditDialog()" immediate="true" ajaxSingle="true">
<h:graphicImage url="/images/edit_icon.png" </h:graphicImage>
<f:param name="arId" id="arId" value="#{vo.assetReceiving.id}"/>
</a4j:commandLink>
其他按钮
<a4j:commandButton id="reData" reRender="data_grid" style="visibility: hidden;" onclick="javascript:alert('rerender clicked');"></a4j:commandButton>
未单击reData按钮. IE的控制台不显示任何消息.这是怎么引起的,我该如何解决?
the reData button does not get clicked. The console of IE does not show any message. How is this caused and how can I solve it?
推荐答案
您需要使用JSF生成的HTML元素ID,而不是JSF组件ID.
You need to use the JSF-generated HTML element ID, not the JSF component ID.
在浏览器中打开页面,右键单击并查看源代码,然后在HTML源代码中找到<a4j:commandButton>
的JSF生成的HTML <input type="submit">
元素.看起来像这样:
Open the page in browser, rightclick and View Source and locate the JSF-generated HTML <input type="submit">
element of the <a4j:commandButton>
in the HTML source. It'll look like this:
<input type="submit" id="someFormId:reData" ... />
您只需要在JavaScript中使用该ID,仅因为JavaScript在HTML DOM树上工作,而不在JSF组件树上工作.
You need to use exactly that ID in JavaScript, simply because JavaScript works on the HTML DOM tree, not on the JSF component tree.
document.getElementById('someFormId:reData').click();
此外,为了使click()
正常工作,最好使用<a4j:commandLink>
而不是<a4j:commandButton>
.
Further you'd better be using <a4j:commandLink>
instead of <a4j:commandButton>
in order to get click()
to work.
这篇关于无法通过JavaScript单击隐藏的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!