.click事件在jquery中不起作用 [英] .click event does not work in jquery

查看:119
本文介绍了.click事件在jquery中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有以下脚本:

I have following script in my page :

$(document).ready(function () {
    $('.RemoveLink').click(function () {

        //dialog box
        $('#dialog').dialog({
            autoOpen: false,
            width: 400,
            modal: true,
            resizable: false
        });

        //end dialog box


        var fileAddress = this.id;
        var parent=$(this).parent().parent();
         $('#dialog').dialog('open');

        $('#dialog').dialog({ /*Initialising a confirmation dialog box (with  cancel/OK button)*/
            buttons: {
                "delete": function () {
                    $(this).dialog('close');

                    $.ajax({

                        url: "url",
                        data: { id: fileAddress },
                        success: function (mydata) {
                        parent.hide();
                            //$('#FileThumbs .ImageFileItem[id=' + fileAddress + ']').hide();
                        },
                        type: "GET"
                    });
                },
                "cancle": function () { //if the User Clicks the button "cancel"
                    $(this).dialog('close');
                }
            }
        })
        return false;
    });
     $('.ResponseLink').click(function () {
        var idval = this.id;
        $.ajax({
            url: "url",
            data: { id: idval },
            dataType: 'html',
            success: function (mydata) {
                $("#ContactArea").empty().append(mydata);
            },
            type: "GET"
        });
        return false;
    });
});

如您所见,我也使用jquery ui拨号框.当我单击"RemoveLink"类的链接时,它可以正常工作并弹出对话框,但是当我单击"ResponseLink"类的链接,然后单击"RemoveLink"的链接后,该页面将不会显示对话框和链接用作普通链接.

as you can see I also use jquery ui dial box. when I click a link with 'RemoveLink' class it works properly and dialog pops-up, but after I click on a link with 'ResponseLink' class and then click on a link with 'RemoveLink', the page does not show dialog and link works as a normal link.

你能帮我吗?

已更新:我正在使用asp.net mvc及其部分视图.我将某些表单放在局部视图中,并使用Ajax.BeignForm()方法将表单异步发送给表单,但有一点要注意.为了使验证与Aj​​ax.BeignForm()一起使用,即使我在调用局部视图的视图中引用了主题,也应该引用必要的脚本.我删除了那些重新引用的脚本,现在再次出现对话框,但是我丢失了表单上的客户端验证!!!!

Updated : I Am using asp.net mvc , and its partial views. I put some form in a partial view and used Ajax.BeignForm() method for form to send it asynchronously, but there is a point. To make validation work with Ajax.BeignForm() I should reference necessary scripts, even though I have referenced theme in a view that calls partial view. I removed those re-referenced scripts and now dialog appears again, but I lost client side validation on form!!!!!

推荐答案

请改用 .delegate .click

$('#ContactArea').delegate('.RemoveLink', 'click', function (e) {...

在您的情况下,您要将click事件附加到附加click事件处理程序时出现的.RemoveLink元素上.一旦您清空并清除了这些内容,它们就会被没有附加事件处理程序的一组新元素替换.

In your case, you are attaching the click event to the .RemoveLink elements that were present at the time of attaching the click event handlers. Once you empty and clear out, those are replaced by new set of elements which don't have the event handler attached.

使用.delegate将确保#ContactsArea中的内容发生更改,但其中的.RemoveLink元素将继续得到处理.在文档中阅读更多内容.

Using .delegate will make sure that however the content inside #ContactsArea changes, the .RemoveLink elements inside it will continue to be handled. Read more up on it in the docs.

这篇关于.click事件在jquery中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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