发布于2021-06-16 05:59 阅读(1188) 评论(0) 点赞(29) 收藏(3)
我正在尝试使用 javascript 验证表单。该函数被正确调用并显示警报,但在我单击警报后仍提交表单。该函数从不返回 false。我之前看过这个问题,但我还没有看到有效的答案。我正在使用一些 JQuery 移动设备,这可能是问题所在。我试图更改按钮输入类型=按钮,但这甚至不会提交表单。
javascript函数是:
<script>
function validateInventoryform()
{
var sku=document.getElementById('sku_checkbox');
var entire=document.getElementById('entire_checkbox');
var inv=document.getElementById('inv');
if ((sku.checked==true && entire.checked==true))
{
alert("You may only choose one option to check customer inventory");
return false;
}
}
</script>
表格是:
<div data-role="popup" id="popupQuery_inventory" data-theme='a' >
<div style="padding:10px 20px;">
<form action="inventory_inquiry.php" method="get" id="inv" onsubmit="return validateInventoryform()" >
<h3>Enter SKU</h3>
<fieldset data-role="controlgroup" data-type="horizontal" data-mini="true">
<legend>Choose Input Type:</legend>
<input type="checkbox" data-theme="a" name="sku_checkbox" id="sku_checkbox" value="off" checked="checked">
<label for="sku_checkbox">SKU</label>
<input type="checkbox" data-theme="a" name="entire_checkbox" id="entire_checkbox" value="off">
<label for="entire_checkbox">Entire Inventory</label>
</fieldset>
<label for="sku" class="ui-hidden-accessible">SKU:</label>
<input type="text" name="sku" id="sku" value="" placeholder="Item SKU" data-theme="a">
<input name="customer_id" type="hidden" value='<?php echo $customer_id; ?>'/>
<button type="submit" data-theme="b"/>Submit</button>
</form>
</div>
</div>
我正在添加调用表单弹出窗口的 href。不知道和这个问题有没有关系。我一直听说我的代码正在被复制并且运行良好。我无法让它工作,我想完整地代表这个问题。
<ul data-role="listview" data-inset="true" data-theme="b">
<li><a href="#popupCustomer_alert" data-rel="popup" data-position-to="origin" data-inline="true" data-transition="pop" >Add Customer Alert</a></li>
<li><a href="#popupQuery_inventory" data-rel="popup" data-position-to="origin" data-inline="true" data-transition="pop" >Query Inventory</a></li>
<li><a href="#popupEdit_customer" data-rel="popup" data-position-to="origin" data-inline="true" data-transition="pop" >Edit Customer</a></li>
<li><a href="return_qr_code.php" >Get QR Code</a></li>
<li><a href="#popupDownload_inventory" data-rel="popup" data-position-to="origin" data-inline="true" data-transition="pop" >Download Inventory</a></li>
</ul>
尝试在 validateInventoryform() 的最后一行添加 return true 并在此删除额外的“/”
<button type="submit" data-theme="b"/>Submit</button>
尝试 Jquery 绑定事件
$(function () {
$('#form').bind('submit', function (e) {
var isValid = true;
if (!isValid) {
e.preventDefault();
}
});
});
作者:黑洞官方问答小能手
链接:http://www.qianduanheidong.com/blog/article/129651/c2c4028b8b335295e6c0/
来源:前端黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 前端黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-3
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!