无法显示jsf隐藏面板组使用javascript
not able to show jsf hidden panelGroup using javascript
我试图显示一个隐藏的panelGroup(LAYOUT=BLOCK)在一个按钮单击。这是我的jsf代码:
<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>
这是我的javascript代码:
//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";
}
}
div显示一秒钟,然后隐藏。我正在使用ajax。谁能告诉我为什么会这样?
您正在使用按钮的onclick
属性来运行一些JavaScript。但是,由于onclick
处理程序不返回false
,因此也执行了单击按钮(提交表单)的默认操作。要防止这种行为,只需将return false
添加到处理程序中。
参见:
- 添加'返回false'到单击事件侦听器?
相关文章:
- PHP Javascript显示/隐藏按钮不工作
- 通过javascript显示和更改文本
- 是否可以用JavaScript显示等效的文件夹对话框
- 如何使用javascript显示图像
- BMI计算器以Javascript显示结果
- 单击“JavaScript显示变量”
- Javascript:显示带有复选框值的图像
- 通过ID JavaScript显示随机背景图像
- 无法在qualtrics上使用javascript显示背景图像
- 日期选择器无法使用javascript显示
- javascript 显示空白灰色层
- 页面加载后通过javascript显示图像
- 使用JavaScript显示鼠标的x和y位置
- 用javascript显示html表
- 使用 JavaScript 显示 Laravel's Variable
- javascript显示地理位置
- 搜索XML文件并使用javascript显示结果
- 使用javascript显示文件名上传
- 使用javascript显示隐藏的HTML元素
- 使用jquery和javascript显示PHP中的变量