目前,在 suggestioinField 组件中添加 ajax 渲染后,div 组件面临问题,div 显示更改为 none。如何使页面保持在同一页面中,甚至在呈现到操作后也考虑过。
这是我用来隐藏和显示股息的 javascript 函数
function AddShow(id){
document.getElementById(id).style.display="block";}
添加按钮以显示div标签:
<h:commandButton type="button" id="cmdadd1" value="#{message.btn__list_add}" onclick="AddShow('Add')" immediate="true"/>
JSF 页面分区内容
<div id="Add" display:none;">
<h:outputLabel value="#{message.label_listA }" />
<o:suggestionField id="addvalA" value="#{MainAction.CodeAdd}" customValueAllowed="false"
manualListOpeningAllowed="true" autoComplete="true" suggestionMinChars="1 onchange="O$.ajax.request(this,event,{ execute: 'frmList: addvalA ', listener: ‘MainAction.doSelectCodeAdd', render: 'frmList' })"onkeydown="O$.ajax.request(this,event,{listener: 'MainAction.doResetA'})" onblur="O$.ajax.request(this,event,{render:'frmList'})" ><o:dropDownItems value="#{MainAction.doCodeAdd}"/> </o:suggestionField>
<h:commandButton id="cmdAddConfirm" value="#{message.btn_create}" >
<f:ajax execute="@form" render="@form" listener="#{MainAction.doConfirmAdd}"/>
</h:commandButton>
</div>
有什么办法可以做到这一点吗?
以下内容添加到您的 js 文件中,我假设您得到了 jQuery(来自素数(,无论如何jsf.ajax.addOnEvent(function (data)...
是重要的部分......
jQuery(window).load(function () {
jsf.ajax.addOnEvent(function (data) {
if (data.status === "success") {
if(data.source.id === "cmdAddConfirm"){
AddShow('Add');
}
}
});
});
简短解释:
在每次 ajax 调用时都会调用jsf.ajax.addOnEvent
,只有在它成功结束之后才会在其中调用,并且只有当调用是从 cmdAddConfirm
按钮进行的时,你才会调用你的 js 函数来设置显示以阻止