单击后按 id 删除元素

remove element by id after clicked

我有动态按钮,从数据库生成。 例如:

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

如果我单击按钮 1,我的函数将向 mysql 数据库发送一些内容,因此我调用 ajax。 但我想要的是:发送到数据库的过程完成后如何删除 button1? 与其他按钮相同(将内容发送到数据库,然后删除按钮)

在我的按钮中我放置了 onClick

这是我的代码:

<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>

但它无法在使用 phonegap

的 jquery 手机上运行

谢谢

你应该使用你所拥有的。 首先,ajax 调用有其 success 回调。你应该在那里删除你的按钮。如果 ajax 呼叫不起作用(服务器无法访问),您的按钮将保留。 其次,您在项目中使用 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 >