gpt4 book ai didi

javascript - EasyUI DateBox - 无法提交表单

转载 作者:行者123 更新时间:2023-11-29 21:15:38 32 4
gpt4 key购买 nike

如何发送包含 EasyUi DateBox 的 HTML 表单?无法提交表格。单击提交按钮时没有任何反应。当我注释掉 DateBox 标签时,表单提交成功。

<!DOCTYPE html> 
<html>
<head>
<meta charset="UTF-8">
<title>DateBox example</title>
<link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.min.js"></script>
<script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

</head>
<body>
<h2>DateBox example</h2>

<form action="showDate.jsp">

<div>
<label for="item">Item name:</label>
<input type="text" id="item" name="itemName" required="required">
</div>
<br>
<div>
<label for="sdate">Shipment date:</label>
<input type="text" class="easyui-datebox" id="sdate"
name="shipmentDate" required="required">
</div>
<input type="submit">

</form>

</body>
</html>

这是 HTML 表单。

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>The date</title>
</head>
<body>
<p>Item name: <%= request.getParameter("itemName")%> </p>
<p>Shipment date: <%= request.getParameter("shipmentDate")%> </p>
</body>
</html>

这是 JSP 页面,它应该接收请求参数。

最佳答案

您遇到此问题似乎是因为 EasyUI 日期框控件在 DOM 中隐藏了您的文本框并插入了它自己的文本框。 EasyUI 不支持新添加的文本框上的 HTML5 required 属性。雪上加霜的是,由于您的原始文本框 [现在已隐藏] 仍然具有 required 属性,因此当 Chrome 尝试对其进行验证时,验证失败并且 Chrome 会尝试将焦点放回您的原始文本框。由于您的现在已隐藏并且无法获得焦点,因此 Chrome 不知道该怎么做并在此时停止该过程。

为了解决这个问题,我的解决方案(如果您想继续使用 HTML 表单验证)是使用 EasyUI 的 api 通过使标记尽可能简单来初始化 EasyUI 日期框控件:

HTML:

<input type="text" id="sdate">

并初始化EasyUI datebox,并直接在新建的EasyUI datebox中添加需要的属性(日期格式模式稍显合理)。

JavaScript:

      $(document).ready(function () {
$('#sdate').datebox(); // Initialize the easyui datebox

// Make the easyui datebox honor HTML5 validation
$('#sdate').datebox('textbox').attr({
'required': 'true',
'pattern': '(?:(?:0[1-9]|1[0-2])[\/\\-. ]?(?:0[1-9]|[12][0-9])|(?:(?:0[13-9]|1[0-2])[\/\\-. ]?30)|(?:(?:0[13578]|1[02])[\/\\-. ]?31))[\/\\-. ]?(?:19|20)[0-9]{2}'
});
});

Working Codepen

就个人而言,我不是这个解决方案(或 EasyUI 控件)的忠实粉丝,因为它是我认为 EasyUI 控件中的缺陷的解决方法,但这应该在紧要关头起作用用于 HTML5 验证。

旁白:EasyUI 日期框确实有它自己的 required 选项,可以在初始化期间传递,但它用于使用 EasyUI 的自定义验证器而不是 HTML5 验证,截至本文撰写时。

来源:

关于javascript - EasyUI DateBox - 无法提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39529533/

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