在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 一個(gè)按鈕實(shí)現(xiàn)插入/刪除的功能

一個(gè)按鈕實(shí)現(xiàn)插入/刪除的功能

用bootstrap table生成一列都為操作的按鈕,當(dāng)我點(diǎn)擊這個(gè)按鈕的時(shí)候在當(dāng)前行的下面一行插入一行內(nèi)容,再點(diǎn)擊這個(gè)按鈕的時(shí)候?qū)⒉迦氲倪@一行刪除,試了好久都不能實(shí)現(xiàn)。下面是我最后只能實(shí)現(xiàn)一次的效果,再點(diǎn)擊就沒有反應(yīng)了。
window.operateEvents = {

    "click #TableEditor": function () {
       $(this).unbind('click');
             var html = '';
    html += '<tr><td colspan="4">';


            html += '<p><b>來電原因:</b>aaa</p>';


    html += '</td></tr>';
    $(this).parent().parent().after(html);

  //  setTimeout(function () {
       // $(this).parent().parent().next().addClass('hide').toggle()
  //  },100)
    //$(this).parent().parent().next().addClass('hide').toggle()
    $(this).click(function () {
        $(this).parent().parent().next().addClass('hide').toggle()
    })
        //  $(this).parent().parent().next().toggle()
   
    }
}
$('table').bootstrapTable({
    url: "getsu",
    columns: [{
        field: "Age",
        title:"年齡"
    }, {
            field: "City",
            title: "城市"
        }, {
            field: "Name",
            title: "姓名",
            events: operateEvents,
            formatter: AddFunctionAlty
        }]
})
function AddFunctionAlty(val) {
    return "<a  id='TableEditor'>" + val + "</a>"
}
回答
編輯回答
瘋浪
$(".class").click(function(){
    // 獲取你要顯示隱藏的節(jié)點(diǎn)的class是否含有hide
    var classHide = $(".class").hasClass("hide");
    if(classHide){
        $(".class").removeClass("hide");
    }else{
        $(".class").addClass("hide");
    }
})

如果不是隱藏顯示 二十動態(tài)加載也是一樣
只不過是獲取的東西不一樣 動態(tài)加載的話就獲取節(jié)點(diǎn)是否存在存在則移除,否則添加
動態(tài)加載我就用個(gè)比較麻煩的寫法,自己簡化吧

$(".class").click(function(){
        // 獲取你要顯示隱藏的節(jié)點(diǎn)的class是否含有hide
    var classHide = $(".class").hasClass("hide");
    if(classHide){
        // 這里是顯示的控制
        // 寫ajax請求,拿數(shù)據(jù)
        $.ajax({
            url: url,
            type: "GET",
            data: data,
            dataType: "json",
            success: function(data){
                // 請求成功將數(shù)據(jù)放入該放的class中
                $(".class").html(data.data.......)
            },
            error: function(e){
                errorfn(e);
            }
        })
        // 將隱藏的class類移除
        $(".class").removeClass("hide");
    }else{
        $(".class").addClass("hide");
    }
})
2018年6月6日 17:38