jQuery确认取消仍然提交表单



即使我取消确认,表格仍然提交 问题出在哪里?我认为我的jquery是错误的,请帮助

窗体外部的"我的按钮">

<li><a id="recieve_btn" href="javascript:void(0)" class="btn animated infinite pulse" onclick="if(!confirm('Are you sure?')) return false;"><span class="glyphicon glyphicon-transfer"></span> Recieve</a></li>

我的表格

<form id="frm-list" action="<?php echo base_url('home/recieve') ?>">
		<table class="table table-condensed display dataTable dt-checkboxes-select" id="list" style="width: 100%;">	
		<thead>
			<tr>
				<th>No</th>
				<th>Family Name</th>
				<th>Given Name</th>
				<th>Middle Initial</th>
				<th>Birthdate</th>
				<th>Module Enrolled</th>
				<th>Action</th>
			</tr>
		</thead>
		<tbody class="datatable">
		<?php foreach ($result as $trainee): ?>
		<tr>
				<td><?php echo $trainee->no ?></td>
				<td><?php echo $trainee->lname ?></td>
				<td><?php echo $trainee->fname ?></td>
				<td><?php echo $trainee->mi ?></td>
				<td><?php echo $trainee->bdate ?></td>
				<td><?php echo $trainee->module ?></td>
				<td>
					<a href="javascript:void(0);" class="btn btn-primary btn-sm animated infinite pulse" data-registerid="<?php echo $trainee->no ?>" id="update">Update</a>
				</td>
			</tr>
		<?php endforeach ?> 
		</tbody>
		<tfoot>
			<tr>
				<th></th>
				<th>Family Name</th>
				<th>Given Name</th>
				<th>Middle Initial</th>
				<th>Birthdate</th>
				<th>Module Enrolled</th>
				<th>Action</th>
			</tr>
		</tfoot>
	</table>
	</form>

我的j查询提交表单

$(document).on('click', '#recieve_btn', function(){
			$('#frm-list').trigger('submit');
		});

不要将内联 Java 脚本代码与 jQuery 混合使用,请尝试以下操作:

$(document).on('click', '#recieve_btn', function() {
//$('#frm-list').trigger('submit');
if (confirm('Are you sure?')) {
console.log('confirmed');
return true;
} else {
console.log('unconfirmed');
return false;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><a id="recieve_btn" href="javascript:void(0)" class="btn animated infinite pulse"><span class="glyphicon glyphicon-transfer"></span> Recieve</a></li>

请尝试此代码。 它可能会对您有所帮助。

$(document).on('click', '#recieve_btn', function() {
if (confirm('Are you sure?')) {
$('#frm-list').trigger('submit');
} else {
return false;
}
});

最新更新