[英]Dojo DateTextBox doesn't work
I am trying to implement dojo date. 我正在尝试实施道场日期。 I am trying example from official website, but it does not work.
我正在尝试从官方网站获取示例 ,但是它不起作用。 Am I missing something here?
我在这里想念什么吗?
<!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>
In your code in the dojoconfig
you are specifying that the parseOnload
to false , so the HTML will not be parsed as a dijit
component. 在你的代码
dojoconfig
您指定的parseOnload
为false,所以HTML不会被解析为dijit
组成部分。
The solution is to set it to true ( call parser.parse())
or create the callback function in the require section as below : 解决方案是将其设置为true(
call parser.parse())
或在require部分中创建回调函数,如下所示:
require(["dojo/parser", "dijit/form/DateTextBox"],function(parser,data){
parser.parse();
});
then , for the style you have to import a dojo css theme and add it's class the body
tag , in the below code I'm using [claro][2]
theme so I've add the to the body it's class =>
<body class="claro">
然后,对于样式,您必须导入dojo css主题并将其添加到
body
标签类中,在下面的代码中,我正在使用[claro][2]
主题,因此我将the添加到主体中是class =>
<body class="claro">
Example 1 : you can test the above complete example using parseOnload:true
: 示例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>
Example 2 : by setting parseOnload:false
and using callback function + parser.parse()
: 示例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>
That's all . 就这样 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.