如何通过使用JavaScript获得JSF selectBooleanCheckbox的值? [英] How to get a value of JSF selectBooleanCheckbox by using JavaScript?

查看:39
本文介绍了如何通过使用JavaScript获得JSF selectBooleanCheckbox的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个名为"bean"的backingbean中仅将布尔值保存在selectBooleanCheckbox中.要在我的JSF xhtml页面中为此复选框设置标签,请使用JSF outputText组件.

I save in my selectBooleanCheckbox only boolean values in a backingbean which named "bean". To set a label for this checkbox in my JSF xhtml page i´m using a JSF outputText component.

这是JSF代码(此示例中有2个复选框):

Here is the JSF code (they are 2 checkboxes in this example):

<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事件:

Now i want to get the selected checkboxes with java script. I´m using the onselect event:

<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组件连接起来?

But this gets only the boolean values of the selected checkboxes. Is it possible to get the value of the outputText components? Is tehre any way to connect the output component with the selectBooleanCheckbox component?

推荐答案

您应该给组件一个唯一的ID,然后尝试通过它们的ID在Java脚本中获取这些值,也可以使用'onclick'来调用Java脚本方法.例如:

You should give a unique ID to the components and then try getting these values in java script by their ID , Also you can use 'onclick' to call the java script method. for ex:

<h:selectBooleanCheckbox id="firstBox" class="extern" value="#{bean.booleanValue1}"       onclick="update(this)"/>
<h:outputText id="firstOutput" value="My Labeltext1"/>

您的Java脚本函数如下所示:

And your java script function would look something like this:

  function update(val){
         var box= document.getElementById("firstBox");
         var outPut = document.getElementById("firstOutput");
        var boxValue = box.value;
        var outPutValue = outPut.value;
 }

这篇关于如何通过使用JavaScript获得JSF selectBooleanCheckbox的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆