gpt4 book ai didi

javascript - Dojo DateTextBox 不起作用

转载 作者:行者123 更新时间:2023-11-30 15:40:58 25 4
gpt4 key购买 nike

我正在尝试实现 dojo 日期。我正在尝试 example从官方网站,但它不工作。我在这里遗漏了什么吗?

<!DOCTYPE html>
<html>
<head>
<script>dojoConfig = {async: true, parseOnLoad: false}</script>
<script src="resources/js/dojo-release-1.10.0/dojo/dojo.js"></script>
<script>
require(["dojo/parser", "dijit/form/DateTextBox"]);
</script>
</head>
<body>
<div>
<label for="fromDate">From:</label>
<input data-dojo-id="myFromDate" type="text" name="fromDate" data-dojo-type="dijit/form/DateTextBox" required="true"
onChange="myToDate.constraints.min = arguments[0];"/>
<label for="toDate">To:</label>
<input data-dojo-id="myToDate" type="text" name="toDate" data-dojo-type="dijit/form/DateTextBox" required="true"
onChange="myFromDate.constraints.max = arguments[0];"/>
</div>
</body>
</html>

最佳答案

在你的代码中dojoconfig您正在指定 parseOnload为 false ,因此 HTML 不会被解析为 dijit成分。

解决方案是将其设置为 true(call parser.parse()) 或在 require 部分创建回调函数,如下所示:

require(["dojo/parser", "dijit/form/DateTextBox"],function(parser,data){
parser.parse();
});

然后,对于样式,您必须导入 dojo css theme并添加它的类 body标签,在下面的代码中我使用了 [claro][2]主题,所以我将其添加到它的类 =><body class="claro">

示例 1:您可以使用 parseOnload:true 测试上面的完整示例:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/claro/claro.css">
<script>dojoConfig = {async: true, parseOnLoad: true}</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<script>
require(["dojo/parser", "dijit/form/DateTextBox"]);
</script>
</head>
<body class="claro">
<div>
<label for="fromDate">From:</label>
<input data-dojo-id="myFromDate" type="text" name="fromDate" data-dojo-type="dijit/form/DateTextBox" required="true"
onChange="myToDate.constraints.min = arguments[0];"/>
<label for="toDate">To:</label>
<input data-dojo-id="myToDate" type="text" name="toDate" data-dojo-type="dijit/form/DateTextBox" required="true"
onChange="myFromDate.constraints.max = arguments[0];"/>
</div>
</body>
</html>

示例 2:通过设置 parseOnload:false并使用回调函数 + parser.parse() :

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/claro/claro.css">
<script>dojoConfig = {async: true, parseOnLoad: false}</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<script>
require(["dojo/parser", "dijit/form/DateTextBox"],function(parser,data){
parser.parse();
});
</script>
</head>
<body class="claro">
<div>
<label for="fromDate">From:</label>
<input data-dojo-id="myFromDate" type="text" name="fromDate" data-dojo-type="dijit/form/DateTextBox" required="true"
onChange="myToDate.constraints.min = arguments[0];"/>
<label for="toDate">To:</label>
<input data-dojo-id="myToDate" type="text" name="toDate" data-dojo-type="dijit/form/DateTextBox" required="true"
onChange="myFromDate.constraints.max = arguments[0];"/>
</div>
</body>
</html>

就是这样。

关于javascript - Dojo DateTextBox 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40825011/

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