且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-05-27 08:57:39

通常页面输入控件想得到日期选择功能,借助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();");

就可以了。













本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/xiandedanteng/p/7608874.html,如需转载请自行联系原作者