![](/img/trans.png)
[英]How to set value of p:selectBooleanCheckbox with JavaScript
[英]How to get a value of JSF selectBooleanCheckbox by using JavaScript?
我在一个名为“ bean”的backingbean中仅将布尔值保存在selectBooleanCheckbox中。 要在我的JSF xhtml页面中为此复选框设置标签,请使用JSF outputText组件。
这是JSF代码(此示例中有2个复选框):
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue1}" />
<h:outputText value="My Labeltext1"/>
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue2}" />
<h:outputText value="My Labeltext2"/>
现在,我想使用Java脚本获取选定的复选框。 我正在使用onselect事件:
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue1}" onselect="MyObject.update(this.options[this.selectedIndex].text);"/>
<h:outputText value="My Labeltext1"/>
<h:selectBooleanCheckbox class="extern" value="#{bean.booleanValue2}" onselect="MyObject.update(this.options[this.selectedIndex].text);"/>
<h:outputText value="My Labeltext2"/>
但这只会获取所选复选框的布尔值。 是否可以获取outputText组件的值? 有什么办法可以将输出组件与selectBooleanCheckbox组件连接起来?
您应该为组件赋予唯一的ID,然后尝试通过其ID在Java脚本中获取这些值,也可以使用“ onclick”调用Java脚本方法。 例如:
<h:selectBooleanCheckbox id="firstBox" class="extern" value="#{bean.booleanValue1}" onclick="update(this)"/>
<h:outputText id="firstOutput" value="My Labeltext1"/>
而且您的Java脚本函数看起来像这样:
function update(val){
var box= document.getElementById("firstBox");
var outPut = document.getElementById("firstOutput");
var boxValue = box.value;
var outPutValue = outPut.value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.