调用Javascript函数f:selectitems的变化

Call Javascript function onchange of f:selectitems

本文关键字:selectitems 变化 Javascript 函数 调用      更新时间:2023-09-26

我是jquery新手。我的项目涉及到primefaces 4.0, jsf 2.1 (xhtml)。

我有一个选择所有布尔复选框,和一个selectmanycheckbox,这是使用从服务器端检索列表填充。

<p:tab title="Service Status" >
    <p:selectBooleanCheckbox itemLabel="Select All"
        value="#{myBean.selectAllStatus}"
        id="selectAllStatus" style="margin-left:4px;" onchange="selectAllStatus(this);" >
    </p:selectBooleanCheckbox>
    <p:selectManyCheckbox
        value="#{myBean.serviceStatusFilterList}"
        layout="pageDirection" id="empListSub">
        <f:param name="tabValue" value="1" />
        <f:selectItems value="#{serviceCalendarViewBean.serviceStatusList}" var="status"
            itemLabel="#{status.title}" itemValue="#{status.id}"/>
    </p:selectManyCheckbox>
</p:tab>
</p:accordion>

点击'select all'复选框时调用的Javascript是

function selectAllStatus(element)
{
   var selectAll = element.checked;
   $( 'input[id^="'accord:empListSub'"]' ).each(function(){
        this.checked=selectAll;
   });
}

当我取消选中'select all'复选框时,我需要f: selectis生成的所有复选框都被选中,反之亦然。

下面的代码在更改事件的javascript中给了我一个控制台错误。错误是"意外语法错误;"

$( 'input[id^="'accord:empListSub'"]' ).each(function(){
    this.checked=selectAll;
});

在网络中javascript代码显示为

$( 'input[id^=&quot;'accord:empListSub'&quot;]' ).each(function(){
     this.checked=selectAll;
});

我试着去掉双引号,但是没有用。

有谁能帮我一下吗?

在jquery中,当我取消选中'select all'复选框时,我需要f:selectitems生成的所有复选框都被选中,反之亦然

并且当我选中或取消选中任何f:selectItems时,它还必须调用另一个javascript函数

我该怎么做?

问题出在组件引用

$( 'input[name^=accord'':empListSub]' ).each(function(i,obj){
    $('div .ui-chkbox-box').addClass('ui-state-active');
    $('span .ui-chkbox-icon').addClass('ui-chkbox-icon ui-icon ui-icon-check ui-c');
 );

尝试在jQuery中使用prop()来设置checked属性

 $( 'input[id^='+accord:empListSub+']' ).prop("checked",selectAll);