Dojo / Dijit - DateTextBox隐藏了我的初始值

时间:2009-09-03 03:42:54

标签: javascript html dojo

演示:http://3wcloud-com-provisioning-qa.appspot.com/testDijitDate

日历弹出窗口工作正常,让我选择一个新的日期。 但是当页面加载时,我看到08/15/2009的日期闪过一会儿,然后就消失了。有没有什么理由CSS或JS会默认隐藏它?

dojo.require("dijit.form.DateTextBox");
<link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/resources/dojo.css" rel="stylesheet" />
<link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dijit/themes/claro/claro.css" rel="stylesheet" />
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js" djConfig="parseOnLoad:true"></script>

<body class="claro">
  <input id="startDate" name="startDate" dojoType="dijit.form.DateTextBox" required=true value="08/15/2009" />

我还在学习使用FireBug。我可以通过浏览DOM找出价值吗?

Firebug显示:

<!-- <input type=text name=startDate size=10 value=""> -->
<div wairole="presentation" dojoattachevent="onmouseenter:_onMouse,onmouseleave:_onMouse,onmousedown:_onMouse" id="widget_startDate" class="dijit dijitReset dijitInlineTable dijitLeft dijitTextBox dijitDateTextBox" role="presentation" widgetid="startDate">
  <div style="overflow: hidden;">
    <div class="dijitReset dijitValidationIcon">
      <br/>
    </div>
    <div class="dijitReset dijitValidationIconText">Χ</div>
    <div class="dijitReset dijitInputField">
      <input type="text" autocomplete="off" dojoattachpoint="textbox,focusNode" class="dijitReset" aria-valuenow="" aria-invalid="true" id="startDate" tabindex="0" aria-required="true" value="" />
      <input type="text" style="display: none;" name="startDate" />
    </div>
  </div>
</div>

2 个答案:

答案 0 :(得分:3)

Dojo仅在标记中使用ISO8601 / RFC3339样式的日期。只要标记中需要日期值,您应该将其专门指定为yyyy-mm-dd 从JavaScript设置日期属性时,应使用Date对象:

dojo.require("dijit.form.DateTextBox");
dojo.addOnLoad(function() {
  // make the date text box
  var startDateTextBox = new dijit.form.DateTextBox({
    value: new Date(2009, 7, 15)
  }, "startDate");
});
<link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/resources/dojo.css" rel="stylesheet" />
<link href="http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dijit/themes/claro/claro.css" rel="stylesheet" />
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js" djConfig="parseOnLoad:true"></script>

<body class="claro">
  <input id="startDate" name="startDate" dojoType="dijit.form.DateTextBox" required=true value="2009-08-15" />

答案 1 :(得分:0)

当DateTextBox将自身应用于输入字段时,看起来Dijit会清除该值。我不确定为什么当dijit控件绑定到输入时不会保留value属性。但是,DateTextBox在API中具有value属性;您可以尝试以编程方式在构造函数选项中使用此值来构造它,而不是使用dojoType属性。我认为它看起来像:

dojo.addOnLoad(function(){
    // make the date text box
        var startDateTextBox = new dijit.form.DateTextBox({
             value: "08/15/2009"
        }, "startDate");
});

HTH