网页上有多个 Facebox:单独的事件?

发布于 2024-11-01 08:27:33 字数 4385 浏览 1 评论 0原文

我的网页中有两个 Facebox。但我的问题是两个 Facebox 中的提交按钮,无论我对第一个 Facebox 发出什么警报,它也会向我的第二个 Facebox 发出警报。

我之所以有两个facebox,是因为我有一个包含两个表单的菜单,然后每个表单都使用facebox。

菜单:
配置播客      

当我触发提交按钮来配置播客表单时上传音乐。它将触发一条消息“播客描述已被编辑”。然后,当我要单击上传音乐中的提交按钮时,在以上传音乐表单显示我的消息之前,也会显示配置播客表单中的消息。请帮忙,

这是我的两种表单的代码:

<br/>
For upload music:
<br/><br/>

<script>
    $(document).ready(function(){
    $('#audioFile').uploadify({
            'uploader'  : 'jquery/js/uploadify/uploadify.swf',  
            'script'    : 'jquery/js/uploadify/uploadify.php',
            'cancelImg' : 'jquery/js/uploadify/cancel.png', 
            'folder'    : 'uploaded/podcastUpload/audio',
            'fileExt'   : '*.mp3',
            'method'    : 'post',
            'fileDesc'  : 'MP3 Files',
            'onComplete'  : function(event, ID, fileObj, response, data) {
                $(".close").click();
                        for (var i=0; i < document.jform.explicit.length; i++)
                        {
                            if (document.jform.explicit[i].checked){
                                var rad_val = document.jform.explicit[i].value;
                            }
                        }
                        var dataString = 'action=PodcastData&jobid=<?=$jobid?>&title=' + $("#title").val() + '&authorName=' + $("#authorName").val() + '&authorEmail=' + $("#authorEmail").val() + '&description=' + $("#description").val() + '&categories=' + $("#categories").val() + '&keywords=' + $("#keywords").val() + '&explicit=' + rad_val + '&fileNameAudio=' + fileObj.name + '&linkAudio=' + fileObj.filePath;
                        $.ajax({
                        cache: 'false',
                        type: "POST",  
                        url: "ajaxfunction.php",  
                        data: dataString,
                        success: function(msg){
                                    $(".close").click();
                                    alert('File Has been uploaded successfully!');
                            }
                        }); 
                    }
            });

    $(".submit").click(function(){
        javascript:$('#audioFile').uploadifyUpload($('.uploadifyQueueItem').last().attr('id').replace('audioFile','')); 
    });
});

<br/><br/><br/><br/><br/><br/><br/>

对于配置 POdcast:

<br/><br/>
    <script>
        $(document).ready(function(){

        $('#imageFile').uploadify({
            'uploader'  : 'jquery/js/uploadify/uploadify.swf',  
            'script'    : 'jquery/js/uploadify/uploadify.php',
            'cancelImg' : 'jquery/js/uploadify/cancel.png', 
            'folder'    : 'uploaded/podcastUpload/image',
            'fileExt'   : '*.jpg;*.gif;*.jpeg',
            'fileDesc'    : 'Image Files',
            'method'    : 'post',
            'onComplete'  : function(event, ID, fileObj, response, data) {
                $(".close").click();
            }
        });
            $(".submit").click(function(){  
                javascript:$('#imageFile').uploadifyUpload($('.uploadifyQueueItem').last().attr('id').replace('imageFile',''));
                for (var i=0; i < document.pDescrForm.pExplicit.length; i++)
                {
                    if (document.pDescrForm.pExplicit[i].checked){
                        var rad_val = document.pDescrForm.pExplicit[i].value;
                    }
                }

                var dataString = 'action=newPodcastDescr&jobid=<?=$jobid?>&pTitle=' + $("#pTitle").val() + '&pAuthorName=' + $("#pAuthorName").val() + '&pAuthorEmail=' + $("#pAuthorEmail").val() + '&pDescr=' + $("#pDescr").val() + '&pSubtitle=' + $("#pSubtitle").val() + '&pCopyright=' + $("#pCopyright").val() + '&pExplicit=' + rad_val;
                $.ajax({
                cache: 'false',
                type: "POST",  
                url: "ajaxfunction.php",  
                data: dataString,
                success: function(msg){
                    $(".close").click();
                    alert('New Podcast description has been added');
                    }
                }); 
            });
        });
</script>

I have two facebox in a webpage. But my problem is the submit button in both facebox, whatever the alert i made to my first facebox, it will also going to alert to my second facebox.

The reason here why I am having two facebox, because I have a menu with two forms, then every form uses facebox.

Menu:
configure podcast         Upload Music

When I fire on submit button to configure podcast form. It will fire a message "Podcast Description has been edited". Then when I going to click on the submit button in Upload Music, the message in configure podcast form will also be displayed before displaying my message in upload music form. Please Help,

Heres the code of my two forms:

<br/>
For upload music:
<br/><br/>

<script>
    $(document).ready(function(){
    $('#audioFile').uploadify({
            'uploader'  : 'jquery/js/uploadify/uploadify.swf',  
            'script'    : 'jquery/js/uploadify/uploadify.php',
            'cancelImg' : 'jquery/js/uploadify/cancel.png', 
            'folder'    : 'uploaded/podcastUpload/audio',
            'fileExt'   : '*.mp3',
            'method'    : 'post',
            'fileDesc'  : 'MP3 Files',
            'onComplete'  : function(event, ID, fileObj, response, data) {
                $(".close").click();
                        for (var i=0; i < document.jform.explicit.length; i++)
                        {
                            if (document.jform.explicit[i].checked){
                                var rad_val = document.jform.explicit[i].value;
                            }
                        }
                        var dataString = 'action=PodcastData&jobid=<?=$jobid?>&title=' + $("#title").val() + '&authorName=' + $("#authorName").val() + '&authorEmail=' + $("#authorEmail").val() + '&description=' + $("#description").val() + '&categories=' + $("#categories").val() + '&keywords=' + $("#keywords").val() + '&explicit=' + rad_val + '&fileNameAudio=' + fileObj.name + '&linkAudio=' + fileObj.filePath;
                        $.ajax({
                        cache: 'false',
                        type: "POST",  
                        url: "ajaxfunction.php",  
                        data: dataString,
                        success: function(msg){
                                    $(".close").click();
                                    alert('File Has been uploaded successfully!');
                            }
                        }); 
                    }
            });

    $(".submit").click(function(){
        javascript:$('#audioFile').uploadifyUpload($('.uploadifyQueueItem').last().attr('id').replace('audioFile','')); 
    });
});

<br/><br/><br/><br/><br/><br/><br/>

For configure POdcast:

<br/><br/>
    <script>
        $(document).ready(function(){

        $('#imageFile').uploadify({
            'uploader'  : 'jquery/js/uploadify/uploadify.swf',  
            'script'    : 'jquery/js/uploadify/uploadify.php',
            'cancelImg' : 'jquery/js/uploadify/cancel.png', 
            'folder'    : 'uploaded/podcastUpload/image',
            'fileExt'   : '*.jpg;*.gif;*.jpeg',
            'fileDesc'    : 'Image Files',
            'method'    : 'post',
            'onComplete'  : function(event, ID, fileObj, response, data) {
                $(".close").click();
            }
        });
            $(".submit").click(function(){  
                javascript:$('#imageFile').uploadifyUpload($('.uploadifyQueueItem').last().attr('id').replace('imageFile',''));
                for (var i=0; i < document.pDescrForm.pExplicit.length; i++)
                {
                    if (document.pDescrForm.pExplicit[i].checked){
                        var rad_val = document.pDescrForm.pExplicit[i].value;
                    }
                }

                var dataString = 'action=newPodcastDescr&jobid=<?=$jobid?>&pTitle=' + $("#pTitle").val() + '&pAuthorName=' + $("#pAuthorName").val() + '&pAuthorEmail=' + $("#pAuthorEmail").val() + '&pDescr=' + $("#pDescr").val() + '&pSubtitle=' + $("#pSubtitle").val() + '&pCopyright=' + $("#pCopyright").val() + '&pExplicit=' + rad_val;
                $.ajax({
                cache: 'false',
                type: "POST",  
                url: "ajaxfunction.php",  
                data: dataString,
                success: function(msg){
                    $(".close").click();
                    alert('New Podcast description has been added');
                    }
                }); 
            });
        });
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

累赘 2024-11-08 08:27:33

在音乐形式代码中查看此代码:

$(".submit").click(function(){ ...

然后在播客形式代码中找到相同的代码。您的提交按钮与点击事件绑定两次。 jQuery 选择器找到所有匹配的元素,并将事件绑定到所有元素。如果您第二次绑定事件,jQuery 会创建一系列事件回调,并依次运行它们。

更改提交按钮的类(因为您需要唯一的选择器),或者如果您不想破坏 css,则添加另一个(即音乐和播客)并按如下方式使用它:

$(".submit.music").click(function() { ...
$(".submit.podcast").click(function(){ ...

这应该只触发一个回调。

Look at this code in music form code:

$(".submit").click(function(){ ...

And then find the same in podcast form code. Your submit buttons are bound with click event twice. jQuery selectors find all the matching elements, and bind event to all of them. If you bind event second time, jQuery make stack of event callbacks, and run them one after another.

Change the classes of submit button (because you need unique selectors) or if you dont want to destroy css add another (i.e. music and podcast) and use it as follows:

$(".submit.music").click(function(){ ...
$(".submit.podcast").click(function(){ ...

This should trigger only one callback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文