これが私の入力コードです
@foreach (entrepreneurs as entrepreneur)
<form name="ent-from" id="ent-form">
<input type="hidden" name="entrepreneur_id" id="entrepreneur_id" value="{{ $entrepreneur->id }}" readonly>
</form>
<button type="button" class="btn btn-custom" id="accept-btn">Accept</button>
@endforeach
アヤックス
$('#accept-btn').on('click', function() {
var entrepreneur_id = $('#entrepreneur_id').val();
alert(entrepreneur_id);
});
コントローラ
public function handleAdmin()
{
$entrepreneurs = Entrepreneur::paginate(5);
return view('handleAdmin', compact('entrepreneurs'));
}
複数の要素にIDを与えることはできません。クラスを使用する必要があります。複数のIDを指定しているため、最初に発生したクリックイベントのみを追跡します。クラスごとに管理する必要があります。
@foreach (entrepreneurs as entrepreneur)
<form name="ent-from" id="ent-form">
<input type="hidden" name="entrepreneur_id" id="entrepreneur_id" value="{{ $entrepreneur->id }}" readonly>
</form>
<button type="button" class="btn btn-custom accept-btn" data-id="{{ $entrepreneur->id }}">Accept</button>
@endforeach
jquery
$('.accept-btn').on('click', function() {
var entrepreneur_id = $(this).data('id');
alert(entrepreneur_id);
});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加