Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过ajax运行php页面时,检查javascript中单击了哪个按钮_Javascript_Php_Jquery_Ajax_Forms - Fatal编程技术网

通过ajax运行php页面时,检查javascript中单击了哪个按钮

通过ajax运行php页面时,检查javascript中单击了哪个按钮,javascript,php,jquery,ajax,forms,Javascript,Php,Jquery,Ajax,Forms,我在一篇博客文章上有一个表单,其中显示了两个提交按钮 一个是保存,另一个是删除。例如: <form class="updatepost"> <input type="submit" name="saveupdatebutton" class="saveupdatebutton" value="Save"> <input type="submit" name="deleteupdatebutton" class="deleteupdatebutton" value="

我在一篇博客文章上有一个表单,其中显示了两个提交按钮

一个是保存,另一个是删除。例如:

<form class="updatepost">
<input type="submit" name="saveupdatebutton" class="saveupdatebutton" value="Save">
<input type="submit" name="deleteupdatebutton" class="deleteupdatebutton" value="Delete">
</form>

但这不起作用。任何关于如何确定单击哪个按钮然后执行不同js代码的帮助。

可以尝试以下方法:

$(".saveupdatebutton").click(function(){
     $(this).addClass('activeBtn');
});

$(".updatepost").submit(function(){
   var isSave= $(this).find('.saveupdatebutton').is('.activeBtn');

   if( isSave){
       /* save code*/
   }else{
        /* delete code*/
    }

})

不要在submit事件上运行该代码,而是将其更改为.saveupdatebutton元素的click事件。然后,您可以将其他功能绑定到.deleteupdatebutton元素的单击。太棒了!从来没有想过这样做,但它是一种享受:)只要现在就开始删除ajax调用:)非常感谢!
// JavaScript - Edit Post

$(document).ready(function(){
$(".saveupdatebutton").click(function(){
     DO STUFF ETC...
});
});
$(".saveupdatebutton").click(function(){
     $(this).addClass('activeBtn');
});

$(".updatepost").submit(function(){
   var isSave= $(this).find('.saveupdatebutton').is('.activeBtn');

   if( isSave){
       /* save code*/
   }else{
        /* delete code*/
    }

})