动态创建的文本框想要加上jQuery的datepicker功能变成日期选择控件该怎么办?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动态创建的文本框想要加上jQuery的datepicker功能变成日期选择控件该怎么办?相关的知识,希望对你有一定的参考价值。

通常页面输入控件想得到日期选择功能,借助jQuery是这样实现的:

1.载入css和js

<script src="jqueryui/jquery-ui.js" type="text/javascript"></script>
<link rel="stylesheet" rev="stylesheet" href="jqueryui/jquery-ui.css" type="text/css" />

 

2.对控件调用datepicker(),如

$("#dateTxt").datepicker();

 

但是如果输入框是动态创建的该怎么办呢?

如下:

var inputDate=document.createElement("input");
inputDate.setAttribute("class","field size4");

inputDate.setAttribute("onfocus","$(this).datepicker();");

或是
inputDate.setAttribute("onclick","$(this).datepicker();");

就可以了。

以上是关于动态创建的文本框想要加上jQuery的datepicker功能变成日期选择控件该怎么办?的主要内容,如果未能解决你的问题,请参考以下文章