[英]Why JQuery code does not work when i click on button?
當我單擊按鈕不起作用時,我的 JQuery 代碼有什么問題,我搜索了很多方法,但我的問題沒有解決。 我在其他文件中使用了此代碼,在那里它可以正常工作,但在此文件中不起作用。
這是我的桌子:
<table class="table table-bordered">
<tbody>
<?php
$insideOrders = \App\OutsideModel::where('total_id', '=', $order->order_id)->get();
?>
@foreach($insideOrders as $index => $inside)
<tr>
<td>{{ $index + 1 }}</td>
<td>{{ $inside->menu->name }}</td>
<td>{{ $inside->menu->category->name }}</td>
<td>{{ $inside->order_amount }}</td>
<td>
@if($order->status=='1')
<button id="send_order" class="btn btn-primary btn-xs"
order_id="{{$order->order_id}}">ارسال<i id="send_icon"></i>
</button>
@else
<button class="btn btn-success btn-xs" disabled>ارسال شده</button>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
這是我的 js:- 。
$('table tbody').on('click', 'button', function () {
var order_id = $(this).attr("order_id");
$.ajax({
url: '{{route('sendOrders')}}',
type: 'GET',
dataType: 'json',
data: {
'id': order_id
},
success: function (response) {
if (response) {
alert('ارسال شد!');
window.location.reload();
}
else {
alert('ارسال نشد!')
}
}, error: function (err) {
}
})
});
我解決了我的問題,我把桌子放在下面的潛水中,我不知道當我把它放在潛水中時會發生什么。 但它現在有效。
<div id="apended_tb">
<table class="table table-bordered">
<tbody>
<?php
$insideOrders = \App\OutsideModel::where('total_id', '=', $order->order_id)->get();
?>
@foreach($insideOrders as $index => $inside)
<tr>
<td>{{ $index + 1 }}</td>
<td>{{ $inside->menu->name }}</td>
<td>{{ $inside->menu->category->name }}</td>
<td>{{ $inside->order_amount }}</td>
<td>
@if($order->status=='1')
<button id="send_order" class="btn btn-primary btn-xs"
order_id="{{$order->order_id}}">ارسال<i id="send_icon"></i>
</button>
@else
<button class="btn btn-success btn-xs" disabled>ارسال شده</button>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
然后:-
$('#apended_tb table tbody').on('click', 'button', function () {........}
替換這個
$('table tbody').on('click', 'button', function () {
有以下內容:
$(document).on('click', '#send_order', function () {
並且有一個錯誤更改 order_id 與
data-order_id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.