jQuery Onchange事件未触发-Primefaces-inputText [英] Jquery Onchange event not getting fired - Primefaces - inputText

查看:61
本文介绍了jQuery Onchange事件未触发-Primefaces-inputText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下事件未被调用:

<script>
        $("#inputTxt").change(function() {
            alert("changed");
        }); 
 </script>

inputTxt的代码如下:

The code for inputTxt is as follows:

<p:inputText id ="inputTxt" name="inputTxt" value="#{article.description}"
                    style="border:none; box-shadow:none;"/>

大写的"articleDescription"在名为"articlesInformation"的数据表中定义,该数据表放置在"articleForm"表单上.

The coloumn "articleDescription" is defined in a datatable named "articlesInformation" which is placed on a form "articleForm".

在检查元素时,我发现inputText的ID变为-"articlesInformation:0:inputTxt".可能就是问题所在.

On inspected the element, I found that the id of the inputText becomes - "articlesInformation:0:inputTxt". Probably that is the issue.

查看页面信息说:

    <td role="gridcell">
       <div class="ui-dt-c">
        <input id="articlesInformation:0:inputTxt" name="articlesInformation:0:inputTxt"
         type="text" value="Description of Article 1"
         style="border:none; box-shadow:none;"
         class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" />
       <script id="articlesInformation:0:inputTxt_s"
  type="text/javascript">PrimeFaces.cw('InputText','widget_articlesInformation_0_inputTxt'
    {id:'articlesInformation:0:inputTxt'});
</script></div></td>

应该如何为primefaces组件定义jquery?

How should the jquery be defined for primefaces components?

谢谢, 什卡(Shikha)

Thanks, Shikha

推荐答案

将inputText放在数据表中时,撇号会为其赋予id = datatable_id:row_index:inputText_id.也就是说,第7行的inputText被赋予id = datatable_id:7:inputText_id.尝试以下...

When inputText is placed in datatable, primefaces gives it id = datatable_id:row_index:inputText_id. That is, the inputText in row 7 is given the id = datatable_id:7:inputText_id. Try the below ...

<p:dataTable id="table_Details" var="dataItem" rowIndexVar="rowIndex">
     <p:column id="articleDescription" headerText="Article Description">
        <p:inputText id="inputTxt" name="inputTxt" value="#{article.description}" onchange="inputTextChanged(#{rowIndex})"/>
     </p:column>
</p:dataTable>

function inputTextChanged(rowIndex){
    var str = 'table_Details:' + rowIndex + ':inputTxt';
    var selected = $(document.getElementById(str));
    alert (selected.val());
}

希望这会有所帮助

这篇关于jQuery Onchange事件未触发-Primefaces-inputText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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