简体   繁体   English

jquery (.on) 不适用于 primefaces.ui-fileupload-cancel,为什么?

[英]jquery (.on) does not work with primefaces .ui-fileupload-cancel, why?

I am using primefaces 8.0 and jsf 2.2, and trying to select.ui-fileupload-cancel element using jquery $ function and listen to (.on) but it is not working, when i use (.click) it works just for the first click. I am using primefaces 8.0 and jsf 2.2, and trying to select.ui-fileupload-cancel element using jquery $ function and listen to (.on) but it is not working, when i use (.click) it works just for the first点击。

<ui:composition template="/templates/main.xhtml">

<ui:define name="body">

<script>

    $(document).ready(function(){
        $(".ui-fileupload-cancel").click(function(){
                alert("Works");
        });
    });
                
    $(document).ready(function() {
       $(".ui-fileUpload").on("click",".ui-fileupload-cancel",function() {
            alert("Does not work");
        });
    })
                   
</script>

        <p:accordionPanel id="uploadPanel" activeIndex="null">

            <p:tab id="uploadTab" title="title">
    
                <p:fileUpload 
                    id="upload" listener="#{Controller.uploadListener}"
                    mode="advanced"  update="messages @this"
                    allowTypes="/(\.|\/)(xml)$/" fileLimit="1"
                    oncomplete="uploadcomplete()" onerror="uploadcomplete()" />

                <p:remoteCommand name="uploadcomplete" update="someId anotherId"
                    process="@this" />

                <p:remoteCommand name="doClear"
                    action="#{Controller.doClear}" update="someId anotherId"
                    process="@this" />

                <p:growl id="messages" showDetail="false" />
            </p:tab>
        </p:accordionPanel>

Skinning from primefaces fileUpload doc.从 primefaces 文件上传文件的皮肤。

Class <------------------------------------> Applies Class <------------------------------------> 适用

.ui-fileupload <-------------------------> Main container element .ui-fileupload <-------------------------> 主容器元素

.ui-fileupload-buttonbar <------------> Button bar .ui-fileupload-buttonbar <------------> 按钮栏

.ui-fileupload-choose <------------> Browse button .ui-fileupload-choose <------------> 浏览按钮

.ui-fileupload-upload <------------> Upload button .ui-fileupload-upload <------------> 上传按钮

.ui-fileupload-cancel <------------> Cancel button .ui-fileupload-cancel <------------> 取消按钮

.ui-fileupload-content <------------> Content container .ui-fileupload-content <------------> 内容容器

What am i missing?我错过了什么?

Add the event to document instead of.ui-fileupload将事件添加到文档而不是 .ui-fileupload

 $(document).on("click",".ui-fileupload-cancel",function() {
        alert("Does not work");
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM