首页 > 代码库 > off("click")的使用

off("click")的使用

今天遇到一个奇怪的问题,用鼠标点击一次HTML button,但是从firebug查看,重复发送了N条请求,写alter调试,发现页面点击一次Click,被浏览器重复捕获N次!
    $("ul.list-group li").click(function () {   //改为 $("ul.list-group li").off("click").click(function () { 问题得以解决!
        //debugger;
        //alert(133333);
        $(this).addClass("active").siblings().removeClass("active");
        var loadFile = ‘‘;
        switch ($(this).attr(‘id‘))
        {
            case ‘difficultSupport‘:
                loadFile = "index.php?extendModule-difficultSupport-index-ajax";
                break;
            case ‘protectRight‘:
                loadFile = "index.php?extendModule-protectRight-index-ajax";
                break;
            case ‘venueBooking‘:
                loadFile = "index.php?extendModule-venueBooking-index-ajax";
                break;
            case ‘policyCoduct‘:
                loadFile = "index.php?extendModule-policyCoduct-index-ajax";
                break;
            case ‘legalAid‘:
                loadFile = "index.php?extendModule-legalAid-index-ajax";
                break;
            case ‘psycholConsult‘:
                loadFile = "index.php?extendModule-psycholConsult-index-ajax";
                break;
            case ‘offlineTraining‘:
                loadFile = "index.php?extendModule-protectRight-index-ajax";
                break;
            case ‘askAbout‘:
                loadFile = "index.php?extendModule-askAbout-index-ajax";
                break;
            default:
        }
        $("div #detail").load(loadFile, function (response, status, xhr) {
            $(‘div #detail‘).html(response);
        });
    });

off("click")的使用