Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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
Php Laravel数据表中的调用id_Php_Jquery_Laravel - Fatal编程技术网

Php Laravel数据表中的调用id

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

我使用in-Laravel创建了一个带有过滤器的数据表。我还需要一个自定义列,因此我添加了以下代码:

 ->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");
});