分类: jquery-easyui2012-10-09
19:07 266人阅读 评论(0) 收藏 举报

目录(?)[+]


看了jquery easyui
databox的官方api,还可以加入倒是很简单,但是想要获得他的值和修改值就很费劲,不知道怎么弄,试了n次终于搞定。这里总结一下,供有相同问题的人查询。

1、 官方api介绍

DateBox

Extend from
$.fn.combo.defaults. Override defaults with
$.fn.datebox.defaults

easyui datebox 的使用 ." />

Dependencies

  • combo
  • calendar

Usage


  1. <</span>input id="dd" type="text"></</span>input>


  1. $('#dd').datebox({
  2. required:true
  3. });

Properties

The properties extend from
combo, below is the added properties for datebox.












Name Type Description Default
panelWidth number The drop down calendar panel width. 180
panelHeight number The drop down calendar panel height. auto
currentText string The text to display for the current day button. Today
closeText string The text to display for the close button. Close
okText string The text to display for the ok button. Ok
disabled boolean When true to disable the field. false
formatter function A function to format the date, the function take a 'date'
parameter and return a string value.
 
parser function A function to parse a date string, the function take a 'date'
string and return a date value.
 

Events





Name Parameters Description
onSelect date Fires when user select a date.

Methods

The methods extend from
combo, below is the overridden methods for datebox.







Name Parameter Description
options none Return the options object.
calendar none Get the calendar object.
setValue value Set the datebox value.

2、 基本用法:

1) 加入日期选择框

[javascript] view
plain
copyprint?



  1. $("#dd").datebox({"required":true});

[javascript] view
plain
copyprint?



  1. $("#dd").datebox({"required":true});

在id为dd的input
type=text的输入框加入iquery easyui的日期选择框,且该日期必须输入时,使用(required:
true),否则使用required:false;

2) javascript获取日期选择框的值

使用常用的jquery获取input
type=text的值的方式

[javascript] view
plain
copyprint?



  1. $("#dd").val()

[javascript] view
plain
copyprint?



  1. $("#dd").val()

发现没有反应,取不到值。问了度娘只有才发现原来是使用下面的方式取值:

[javascript] view
plain
copyprint?



  1. $("#dd").datebox("getValue");

[javascript] view
plain
copyprint?



  1. $("#dd").datebox("getValue");


当然这种方式不是太符合我们习惯,那么我们可以给它添加一个事件监听,在datebox onSelect 日期选中后,自动为input
id="dd" type="text"赋值,然后我们就可以使用

$("#dd").val()获取选中的日期值了。

具体代码如下:

[javascript] view
plain
copyprint?



  1. "text/javascript">
  2. $(document).ready(function(){
  3. $("#dd").datebox({
  4. required:true,
  5. onSelect: function(date){
  6. $("#dd").val(date);
  7. }
  8. });
  9. });

[javascript] view
plain
copyprint?



  1. "text/javascript">
  2. $(document).ready(function(){
  3. $("#dd").datebox({
  4. required:true,
  5. onSelect: function(date){
  6. $("#dd").val(date);
  7. }
  8. });
  9. });

3) javascript设置datebox的值

[javascript] view
plain
copyprint?



  1. $("#dd").datebox("setValue", "2012-01-01");

[javascript] view
plain
copyprint?



  1. $("#dd").datebox("setValue", "2012-01-01");

补充:

需求场景:当我们需要把datebox中的设置的值,取得后返回一个Date类型的时候,就发现有些不好办了?

错误用法:

[javascript] view
plain
copyprint?



  1. var tempStr = $("#dd").datebox("getValue");
  2. var tempDate = new Date(tempStr);
  3. return tempDate;

[javascript] view
plain
copyprint?



  1. var tempStr = $("#dd").datebox("getValue");
  2. var tempDate = new Date(tempStr);
  3. return tempDate;


发现在FireFox下,这样做是没有问题的;但是IE下就不起作用了,datebox("getValue")能返回正确的只字符串,例如“2012-01-01",但是new
Date(str)的时候返回为NaN;

查了下Date的API发现,new Date(str)
调用了 Date.parse(str) 函数, 但是在IE下该函数默认支持Str格式为:

MM-dd-yyyy HH:mm:ss

所以我们给定的字符串不是这种格式的,那么就解析不了。

找到原因之后,就好解决了,下面提供一个自己是是实现的函数
parseDate(dateStr)

[javascript] view
plain
copyprint?



  1. function parseDate(dateStr){
  2. var strArray = dateStr.split("-");
  3. if(strArray.length == 3){
  4. return new Date(strArray[0], strArray[1], strArray[2]);
  5. }else{
  6. return new Date();
  7. }
  8. }

[javascript] view
plain
copyprint?



  1. function parseDate(dateStr){
  2. var strArray = dateStr.split("-");
  3. if(strArray.length == 3){
  4. return new Date(strArray[0], strArray[1], strArray[2]);
  5. }else{
  6. return new Date();
  7. }
  8. }

ok,终于知道怎么用了



版权声明:本文为博主原创文章,未经博主允许不得转载。

jquery&nbsp;easyui&nbsp;datebox&nbsp;的使用&nbsp;.的更多相关文章

  1. 第二百一十五节,jQuery EasyUI,DateBox(日期输入框)组件

    jQuery EasyUI,DateBox(日期输入框)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 DateBox(日期输入框)组件的使 ...

  2. EasyUI修改DateBox和DateTimeBox的默认日期格式

      最近整理Easyui控件的时候,对Easyui的DateBox控件和DateTimeBox控件进行了梳理,而我之所以将EasyUI的DateBox控件和DateTimeBox控件放在一起,归为一类 ...

  3. EasyUI改动DateBox和DateTimeBox的默认日期格式

    近期整理Easyui控件的时候,对Easyui的DateBox控件和DateTimeBox控件进行了梳理,而我之所以将EasyUI的DateBox控件和DateTimeBox控件放在一起,归为一类,是 ...

  4. [转][EasyUI]扩展 DateBox

    /** * 给时间框控件扩展一个清除的按钮 */ $.fn.datebox.defaults.cleanText = '清空'; (function ($) { var buttons = $.ext ...

  5. EasyUi–8.datebox赋值的问题

    这个问题要从EasyUI的datebox组件说起,小菜用这个组件的时候,发现用$("#id").val()这种形式,居然拿不到文本框的值!      经过度娘的帮助,发现可以用$( ...

  6. 给EasyUI的DateBox控件添加清除button

     EasyUI中间DateBox控制甚至没有被清除button.例如下面的附图: 真是不可思议,对于要求日期格式必须选择的情况下,不能清空日期,很不方便.      尽管能够通过手工改动EasyU ...

  7. easyui的datebox只显示年月

    要求点击easyui的datebox时只显示年月,隐藏日,之前百度了好多,发现有的好麻烦,有的使用没效果,也许自己没理解,改不了.最后老员工帮我搞定了,添加一个fomatter和一个parser函数就 ...

  8. EasyUi–8.datebox赋值的问题

    这个问题要从EasyUI的datebox组件说起,小菜用这个组件的时候,发现用$("#id").val()这种形式,居然拿不到文本框的值! 经过度娘的帮助,发现可以用$(" ...

  9. easyui的datebox最简单的方法来格式化

    看了网上有很多解决方案,我也写了一个比较简单的方法. 实现easyui的datebox格式化. 效果例如以下.用"++"隔开,看你喜欢用什么都能够. 1.html <span ...

随机推荐

  1. maven scope runtime

    https://blog.csdn.net/ningbohezhijunbl/article/details/25818069 There are 6 scopes available: compil ...

  2. vs2013工程技巧

    1 vs工程输出了dll和lib,分别是什么,有什么用? 当设置工程property的Project Defaults的Configuration Type为dll时,不光会生成该动态链接库的dll文 ...

  3. An Overview of Query Optimization in Relational Systems

    An Overview of Query Optimization in Relational Systems

  4. CMMI过程改进反例

     近期一直在看CMMI的资料,越看认为越有意思.今天看到过程改进的时候,突然想起来之前所在的公司发生的过程改进相关的事儿来. 公司通过CMMI3级认证之后.PMO部门经理(公司还有质量管理部门经理 ...

  5. Java for LeetCode 119 Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  6. IOS UITableView reload 刷新某一个cell 或 section

    通常刷新整个列表 我们都使用[self.tableView reloadData]; 有的时候,有变化更新的只是某一行 row 或者是某个section 所以只更新这一行就好了 //一个section ...

  7. mysql服务突然不能启动

    mysql之前一直用的好好的,今天突然不能启动.前几天改过my.ini文件,在[mysqld]下添加了default-character-set=utf8.查看日志发现是添加的那句话的错误,删除.并且 ...

  8. initcall_debug简要说明【转】

    本文转载自:https://blog.csdn.net/zangdongming/article/details/37769265 Linux version 3.10.40 1. 使用说明 Docu ...

  9. LibreOJ 数列分块入门

    题目链接:https://loj.ac/problem/6277 题目描述 给出一个长为 nnn 的数列,以及 nnn 个操作,操作涉及区间加法,单点查值. 输入格式 第一行输入一个数字 nnn. 第 ...

  10. BZOJ 1685 [Usaco2005 Oct]Allowance 津贴:贪心【给硬币问题】

    题目链接:http://begin.lydsy.com/JudgeOnline/problem.php?id=1333 题意: 有n种不同币值的硬币,并保证大币值一定是小币值的倍数. 每种硬币的币值为 ...