呼唤远方
您可以为 javascript 使用字符串占位符。<input type="hidden" id="_room_id" value="{{ $room->id }}"><input type="hidden" id="_room_project_id" value="{{ $room->id_project }}">let project_id = $('#_room_project_id').val(); // or document.getElementById('_room_project_id').value if you're not using JQuerylet id = $('#_room_id').val(); // or document.getElementById('_room_id').value if you're not using JQuerylet url = "{{ route('datatable.getaccess', [':project_id', ':id']) }}".replace(':project_id', project_id).replace(':id', id);这看起来是错误的,但它可以工作,因为我们将字符串传递给路由助手(这反过来会产生一个字符串)route('datatable.getaccess', [':project_id', ':id'])// 'viewroom/:project_id/:id'所以let url = "{{ route('datatable.getaccess', [':project_id', ':id']) }}".replace(':project_id', project_id).replace(':id', id);相当于let url = "viewroom/:project_id/:id".replace(':project_id', project_id).replace(':id', id);