可以';t使用jQuery Popconfirm插件获取点击按钮的名称


can't get the name of the button clicked using jQuery Popconfirm plugin

所以我决定使用这个插件https://github.com/Ifnot/PopConfirm因为它被推荐为一个很好的确认按钮。我把它设置好了,除了一件事,一切都很好。

我使用单击的按钮的名称在PHP中验证我的所有表单,因为我有几个按钮,如保存、取消、删除。因此,当用PHP提交表单时,我可以使用以下POST变量,并且我可以使用验证按钮

PHP e.g. 
Array ( [supplier] => "david" [customer] => "new buy" [save] => )
Validate Using
if(isset($_POST['save'])){} 

但是当我使用popconfirm插件时,由于它使用.submit()提交表单,在提交表单时,我只得到输入框的值,而没有按钮的名称

Using popconfirm to submit the form, I end up with
Array ( [supplier] => "david" [customer] => "new buy" ) 

由于使用popconfirm时缺少$_POST["保存"],因此我无法验证在PHP中按下了哪个按钮,因为它没有传递。

我可以看到插件使用

form.submit(); 

提交表单,但我不明白的是,为什么按钮的名称没有像PHP那样发布,或者如何让submit函数也传递按钮名称变量

当您使用jQuery(PopConfirm使用)提交表单时,按钮的名称和值不会与其他表单数据一起传递(我不知道确切的原因)
如果您看到jquery.popconfirm.js的来源,您可以通过搜索以下注释行来搜索处理按钮的部分:

    // If the button is a submit one

你会找到处理按钮的部分。将这几行代码添加到form.submit()之前

btnName = typeof(self.attr('name')) === 'undefined' ? '' : self.attr('name');
btnVal = typeof(self.attr('value')) === 'undefined' ? '' : self.val();
form.append('<input type="hidden" name="' + btnName + '" value="' + btnVal + '" />');

现在,这种行为在刚刚起草的最新版本v0.4.5中得到了修复。