No Family Name Given Name Midd-6ren">
gpt4 book ai didi

javascript - jquery确认取消仍然提交表单

转载 作者:行者123 更新时间:2023-11-30 07:31:37 24 4
gpt4 key购买 nike

即使我取消确认,表格仍会提交问题是什么?我认为我的 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>

用于提交表单的 jquery

$(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>

关于javascript - jquery确认取消仍然提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50560245/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com