Php Laravel数据表中的调用id
我使用in-Laravel创建了一个带有过滤器的数据表。我还需要一个自定义列,因此我添加了以下代码:Php Laravel数据表中的调用id,php,jquery,laravel,Php,Jquery,Laravel,我使用in-Laravel创建了一个带有过滤器的数据表。我还需要一个自定义列,因此我添加了以下代码: ->addColumn('estado', function ($previsitas) { return $previsitas->f_salida ? '<a id="delete" class="text-danger" data-toggle="tooltip" data-placement="top" title="Cambiar esta
->addColumn('estado', function ($previsitas) {
return $previsitas->f_salida ? '<a id="delete" class="text-danger" data-toggle="tooltip" data-placement="top" title="Cambiar estado" href="' . route('visitas.estado', [$previsitas->id]) . '"><strong>Salida</strong></a>' :'<a class="text-success" data-toggle="tooltip" data-placement="top" title="Cambiar estado" href="' . route('visitas.estado', [$previsitas->id]) . '"><strong>Entrada</strong></a>';
})->rawColumns(['estado'])
当我在列中单击时,什么都不会发生,但当我在blade中直接创建id为='delete'的元素时,一切都会发生
因此,错误很简单:我不能在datatable列中调用id为的元素,但如果直接在blade中使用,我可以调用该元素。为什么会发生此错误?此代码
$('#delete').click(function () {
swal('Test');
});
可能以前正在执行
->addColumn('estado', function ($previsitas) {
return $previsitas->f_salida ? '<a id="delete" class="text-danger" data-toggle="tooltip" data-placement="top" title="Cambiar estado" href="' . route('visitas.estado', [$previsitas->id]) . '"><strong>Salida</strong></a>' :'<a class="text-success" data-toggle="tooltip" data-placement="top" title="Cambiar estado" href="' . route('visitas.estado', [$previsitas->id]) . '"><strong>Entrada</strong></a>';
})->rawColumns(['estado'])
->addColumn('estado',函数($previsitas){
返回$previsitas->f_salida?“”;
})->rawColumns(['estado']))
被添加到DOM中我认为您需要为此使用jQuery事件委派。当前,调用
$(“#删除”)。单击(…)
会将单击
事件分配给DOM元素$(“#删除”)
,该元素在分配时不存在。如果您将单击事件分配给主体,目标为“#delete”
,这应该适用于您:
$("body").on("click", "#delete", function () {
swal("Test");
});
算了吧,我找到了解决办法。我需要将它添加到JS代码“$('body')。在('click','#delete',function(){});'
$("body").on("click", "#delete", function () {
swal("Test");
});