多次点击复制

时间:2014-03-05 08:30:32

标签: jquery

我这里有一个添加记录。我取消绑定保存按钮以防止重复记录。但问题是当我尝试添加新记录时,保存按钮仍然禁用。我尝试再次使用bind但它不起作用。

请帮助

enter image description here

$(document).ready(function(){

    $("#save").click(function(){
    $('#save').unbind( "click" );
        ajax("save");
    });
    //$(document).on('click', '#save', function() {
    //ajax("save");
    //});

    $("#add_new").click(function(){
        $(".entry-form").fadeIn("fast");
    });

    $("#close").click(function(){
        $(".entry-form").fadeOut("fast");   
    });

    $("#cancel").click(function(){
        $(".entry-form").fadeOut("fast");   
    });

    $(".del").live("click",function(){
        if(confirm("Do you really want to delete this record ?")){
            ajax("delete",$(this).attr("id"));
        }
    });

    function ajax(action,id){
        if(action =="save")
            data = $("#userinfo").serialize()+"&action="+action;
        else if(action == "delete"){
            data = "action="+action+"&item_id="+id;
        }
        $.ajax({
            type: "POST", 
            url: "ajax.php", 
            data : data,
            dataType: "json",
            success: function(response){
            console.log(JSON.stringify(response))
                if(response.success == "1"){
                    if(action == "save"){
                        $(".entry-form").fadeOut("fast",function(){
                            $(".table-list").append("<tr><td>"+response.cat_name+"</td><td>"+response.cat_code+"</td><td>"+response.letter+"</td><td><a href='#' id='"+response.row_id+"' class='del'>Delete</a></td></tr>");   
                            $(".table-list tr:last").effect("highlight", {
                                color: '#4BADF5'
                            }, 0000);
                        }); 
                        $(".entry-form input[type='text']").each(function(){
                            $(this).val("");
                        });

                    }else if(action == "delete"){
                        var row_id = response.item_id;
                        $("a[id='"+row_id+"']").closest("tr").effect("highlight", {
                            color: '#4BADF5'
                        }, 0000);
                        $("a[id='"+row_id+"']").closest("tr").fadeOut();
                    }
                }else{
                    alert("unexpected error occured, Please check your database connection");
                }
            },
            error: function(res){
                alert("Unexpected error! Try again.");
            }
        });
    }
});

0 个答案:

没有答案