在javascript中读取struts2 <s:datetimepicker中的值

<s:datetimepicker id="time1" name="time1" toggleType="explode" value="today" /> 
<s:datetimepicker id="time2" name="time2" toggleType="explode" value="today" />

我们在javascript中可以通过以下方式读取和赋值

var time1= dojo.widget.byId("time1");
var stringtime1 = time1.getValue();//读取
var time2= dojo.widget.byId("time2");
time2.setValue(stringtime1 ); 
//赋值

以上代码,取出time1中的值,赋给time2


Struts2 API中的一个例子:
Examples:
<s:datetimepicker name="order.date" label="Order Date" />
<s:datetimepicker name="delivery.date" label="Delivery Date" displayFormat="yyyy-MM-dd"  />
<s:datetimepicker name="delivery.date" label="Delivery Date" value="%{date}"  />
<s:datetimepicker name="delivery.date" label="Delivery Date" value="%{'2007-01-01'}"  />
<s:datetimepicker name="order.date" label="Order Date" value="%{'today'}"/>

Getting and getting the datetimepicker value, from JavaScript:

<s:datetimepicker id="picker" label="Order Date" />
<script type="text/javascript">
  
function setValue() {
     
var picker = dojo.widget.byId("picker");
     
     
//string value
     picker.setValue('2007-01-01');
     
     
//Date value
     picker.setValue(new Date());
  }

  
  
function showValue() {
     
var picker = dojo.widget.byId("picker");
     
     
//string value
     var stringValue = picker.getValue();
     alert(stringValue);
     
     
//date value
     var dateValue = picker.getDate();
     alert(dateValue);
  }

</script>


Publish topic when value changes:

<s:datetimepicker id="picker" label="Order Date" valueNotifyTopics="/value"/>
<script type="text/javascript">
dojo.event.topic.subscribe(
"/value"function(textEntered, date, widget){
    alert('value changed');
    
//textEntered: String enetered in the textbox
    //date: JavaScript Date object with the value selected
    //widet: widget that published the topic 
}
);
</script>
posted @ 2011-11-29 21:59  Ray.Wang  阅读(533)  评论(0编辑  收藏  举报