无法使用javascript显示jsf隐藏的panelGroup

无法使用javascript显示jsf隐藏的panelGroup,javascript,jsf,Javascript,Jsf,我试图通过单击按钮来显示隐藏的panelGroup(LAYOUT=BLOCK) <h:form id="userSetup" > <h:inputText id="skills" a:placeholder="Skills" class="cff-inputText"></h:inputText> <br/><br/> //when

我试图通过单击按钮来显示隐藏的panelGroup(LAYOUT=BLOCK

 <h:form id="userSetup" >
                    <h:inputText id="skills" a:placeholder="Skills" class="cff-inputText"></h:inputText>
                <br/><br/>
               //when user clicks this button div is shown
                <button class="cff-button"  onclick="toggleCertificateInput('#{certificateInput.clientId}',true)">Add Certificate</button>
                <br/><br/>
                //div to show on button click
                <h:panelGroup id="certificate-input"  layout="block" binding="#{certificateInput}" a:hidden="true">
                    <h:inputText value="#{uploader.certificateName}" class="cff-inputText" a:placeholder="Certificate Name"></h:inputText>
                    <h:inputText value="#{uploader.certificateLink}" class="cff-inputText" a:placeholder="Link"></h:inputText>
                    <h:commandButton value="Save Certificate" class="cff-button" action="#{uploader.saveCertificate()}">
                        <f:ajax  execute="@form" ></f:ajax>
                    </h:commandButton>
                </h:panelGroup>


            </h:form>

div显示一秒钟,然后隐藏。我正在使用ajax。有人能告诉我为什么会发生这种情况吗?

您正在使用按钮的
onclick
属性来运行一些JavaScript。但是,由于
onclick
处理程序不会返回
false
,因此也会执行单击按钮(提交表单)的默认操作。要防止这种行为,只需将
returnfalse
添加到处理程序中即可

另见:


您正在使用按钮的
onclick
属性来运行一些JavaScript。但是,由于
onclick
处理程序不会返回
false
,因此也会执行单击按钮(提交表单)的默认操作。要防止这种行为,只需将
returnfalse
添加到处理程序中即可

另见:


尝试添加
return false
,因此
onclick=“toggleCertificateInput('{certificateInput.clientId}',true);return false”
感谢您的工作!您能解释一下添加return false时发生了什么吗添加
return false
,所以
onclick=“toggleCertificateInput('{certificateInput.clientId}',true);return false”
谢谢您的工作!你能解释一下添加return false时发生了什么吗
//if toggle is true then show the div else hide it
function toggleCertificateInput(inputDivId,toggle){

  inputDiv = document.getElementById(inputDivId);

        if(toggle){
            alert("about to display input div");
          inputDiv.style.display = "block";          
        }else{
            alert("about to hide input div");
          inputDiv.style.display = "none";
        }

}