我试图删除确认执行删除当前id数据的函数。
我收到此错误:
未捕获的TypeError:无法读取属性' call'未定义的
在bootstrap-confirmation.js
return function() {
context[func].call(this);
};
这是我的按钮代码
<button class="btn btn-danger" data-toggle="confirmation"
data- btn-ok- class="btn-danger" data-btn-cancel-icon="glyphicon
glyphicon-ban-circle" data-btn-cancel-class="btn-default"
data-popout="true" data-singleton="true" data-on-confirm="goDel(id)">
Eliminar</button>
这是我的Javascript
<script type="text/javascript">
function goDel(id)
{
location.href="./delete/" + id;
}
</script>
这是我的删除控制器
public function delete($id) {
$clientes = new Clientes();
$codcta = new Codcta();
$this -> codcta = $codcta -> find();
$codciu = new Codciu();
$this -> codciu = $codciu -> find();
$clientes = new clientes();
if ($clientes->delete((int)$id)) {
Flash::valid('El registro se ha eliminado correctamente');
}else{
Flash::error('Falló Operación');
}
return Redirect::to();
}
答案 0 :(得分:7)
在按钮中更改此内容:
data-on-confirm="goDel"
并添加:
data-id="YOUR-ID-HERE"
在你的javascript函数中:
function goDel()
{
var id = $(this)[0].getAttribute('data-id');
location.href="./delete/" + id;
}
祝你好运!
答案 1 :(得分:0)
<button class="btn btn-danger" data-toggle="confirmation" data-title="Title here" data-content="Content here" data-btn-cancel-icon="glyphicon
glyphicon-ban-circle" data-btn-cancel-class="btn-default"
data-popout="true" data-singleton="true" data-on-confirm="deleteMethodName" data-id="your-deleted-id-here">Eliminar</button>
function deleteMethodName()
{
var id = $(this)[0].getAttribute('data-id');
//Now you will get ID from above and use it as you like
}