jquery不跟踪表单更改

时间:2017-08-18 12:18:29

标签: javascript jquery jsf primefaces

我正在研究primefaces应用程序,

最初将显示项目列表,通过单击项目,用户可以编辑项目。

在我的情况下,有五个选项卡,如果用户点击第一个选项卡列表项,将显示第四个选项卡内容,将显示第二个选项卡列表项第五个选项卡上的点击。

所有这些网页的网址都相同

代表:localhost:8080/myapp/tabs.xhtml

<ui:composition xmlns="http://www.w3.org/1999/xhtml">
    <script type="text/javascript">
        $(document).ready(function() {
            isInputChanged = false;
            $("#tabview").on("change", ":input", function() {
                isInputChanged = true;
            })
        });
    </script>
    <p:tabView id="tabview" activeIndex="#{myBean.tabIndex}"
        style="min-height:750px;height:auto;border:0;padding:0" dynamic="true" styleClass="hidetabheader" >

        <p:tab id="tabContents1">  
            <ui:include src="/tabContents1.xhtml"></ui:include>
        </p:tab>            
        <p:tab id="tabContents2">  
            <ui:include src="/tabContents2.xhtml"></ui:include>
        </p:tab>
        <p:tab id="tabContents3">  
            <ui:include src="/tabContents3.xhtml"></ui:include>
        </p:tab>
        <p:tab id="tabContents4">  
            <ui:include src="/tabContents4.xhtml"></ui:include>
        </p:tab>
        <p:tab id="tabContents5">  
            <ui:include src="/tabContents5.xhtml"></ui:include>
        </p:tab>
    </p:tabView>
</ui:define>

通过chrome调试时 问题是由于相同的网址,第四和第五个标签中的输入更改未被跟踪,我的意思是 isInputChanged 永远不会变为 true 。 在chrome调试工具中,源显示始终相同。

但是,如果我在url中添加参数就好了 localhost:8080/myapp/tabs.xhtml?itemId = 100,在源代码中我可以看到第五个标签代码,如果更改输入, isInputChanged 将通过脚本变为 true

如何处理这种情况,提前致谢!!!!!!!!!

1 个答案:

答案 0 :(得分:0)

我认为这是因为以下代码在localhost:8080 / myapp / tabs.xhtml加载时有效。

$("#tabview").on("change", ":input", function() {
    isInputChanged = true;
});

您是否包含此后的文件,以便浏览器无法查看更改。

像@Alive To Die评论一样,尝试将脚本代码放在页面底部,然后检查。