代码之家  ›  专栏  ›  技术社区  ›  Def

单击后按id删除元素

  •  0
  • Def  · 技术社区  · 7 年前

    前任:

    button 1, id=button1
    button 2, id= button2
    button 3, id= button3
    ..etc....
    

    若我点击按钮1,我的函数将向mysql数据库发送一些信息,所以我称之为ajax。 另一个按钮也是一样(发送一些东西到数据库,然后删除按钮)

    在我的按钮上,我点击了一下

    这是我的代码:

    <script>
        function process(idbutton){
        $.ajax({
                      type: "POST",
                      url: "http://urlofmysite.com/process.php?",
                     data: "pidd=" + idbutton,
                      cache: false,
                      success: function(html){
                        alert(html); //RESPONSE FROM SERVER      
                      }
                    }); 
        //REMOVING BUTTON
        document.getElementById(+idbutton+).outerHTML="";
        }
    </script>
    

    谢谢

    1 回复  |  直到 7 年前
        1
  •  0
  •   Herr Derb    7 年前

    你应该使用你所拥有的。 首先,ajax调用具有 success 其次,在项目中使用jQuery。不要混淆jQuery和本机Dom操作函数。使用简单易读的jQuery函数 $('#'+idbutton).remove() 删除按钮。

     < script >
    function process(idbutton) {
        $.ajax({
            type: "POST",
            url: "http://urlofmysite.com/process.php?",
            data: "pidd=" + idbutton,
            cache: false,
            success: function (html) {
                alert(html); //RESPONSE FROM SERVER
                //REMOVING BUTTON
                $('#' + idbutton).remove();
            }
        });
    
    }
    <  / script >