动态生成控件的.datepicker()无法运行 jquery datepickerjquerydatepicker动态生成 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $(function () { $("input[xtype='date']").datepicker(); $("input[xtype='date']").datepicker({ dateFormat: "yy/mm/dd", changeMonth: true, changeYear: true }); $("input[xtype='date']").datepicker("option", $.datepicker.regional["zh-CN"]); //上面的代码有运行,可以显示日期选择控件 $("#childAdd").click(function () { //动态添加一些控件,其中有一个【$("input[xtype='date']")】的控件 //改成这样试试,只给最新添加进去的input设置datepicker var newAdd = $(ChildInfo).appendTo("#ChildTable"); newAdd.find("input[xtype='date']").click(function () { alert("点我");//此句有运行,跳出窗口 //以下代码不知道到底想干嘛,已经是datepicker了,还要在click的时候再绑定datepicker? // $(this).datepicker();//没反应 // $(this).datepicker({ dateFormat: "yy/mm/dd", changeMonth: true, changeYear: true });//没反应 // $(this).datepicker("option", $.datepicker.regional["zh-CN"]);//没反应 }); newAdd.find("input[xtype='date']").datepicker();//没反应 newAdd.find("input[xtype='date']").datepicker({ dateFormat: "yy/mm/dd", changeMonth: true, changeYear: true });//没反应 newAdd.find("input[xtype='date']").datepicker("option", $.datepicker.regional["zh-CN"]);//没反应 });});改成这样试试。 回复2楼,一样的,就alert有运行,其他的没有运行应该是 datepickeer 什么地方有问题吧!? 代码没什么问题,建议你把alert去掉,换成console.log或者直接不要加这行。毕竟alert会阻止JS代码运行的。 回3楼,去掉alert一样不行,本来就是没有alert的,为了调试是否有运行,才加进去alert的 有没有办法用 live 或者 on 整一下? 你要是想动态生成,应该每次都生成标签,然后再使用datepicker,最后附加到相应的元素上显示出来。比如这样——<button id="btn">add</button> <script> $("#btn").click(function () { $("<div></div>").datepicker().appendTo("body"); }); </script>看样子你的写法是input上创建datepicker,接着附加元素,这样就有的元素已经有datepicker而有的没有。你又不加以区别,通通选中,全都绑定click事件,全都使用datepicker。……总的来说你写的太混乱了…… $("input[xtype='date']").live("focus", function () { $(this).datepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true }); }); 帮忙看下DIV显示和隐藏的问题,谢谢 Extjs tree的拖拽后排序问题 ,求教 关于获取点击对象 找了很久都没分析出里边的原理? 高分求助js问题 如何用JAVASCRIPT更新一个超链接字的颜色??? 请教高手帮忙看看这段asp+js代码错在哪里 大家轻松一下,来试用一下这个壁纸 怎么得到IE中一个点相对屏幕的绝对位置? 给input赋值后,再界面改变值,value属性值没变是怎么回事? 怎么把input里面的value值传到from表单action去呢? 百度分享和百度站内搜索在火狐显示正常,在ie8中不显示或显示不正确!
$("input[xtype='date']").datepicker();
$("input[xtype='date']").datepicker({ dateFormat: "yy/mm/dd", changeMonth: true, changeYear: true });
$("input[xtype='date']").datepicker("option", $.datepicker.regional["zh-CN"]);
//上面的代码有运行,可以显示日期选择控件
$("#childAdd").click(function () {
//动态添加一些控件,其中有一个【$("input[xtype='date']")】的控件
//改成这样试试,只给最新添加进去的input设置datepicker
var newAdd = $(ChildInfo).appendTo("#ChildTable");
newAdd.find("input[xtype='date']").click(function () {
alert("点我");//此句有运行,跳出窗口
//以下代码不知道到底想干嘛,已经是datepicker了,还要在click的时候再绑定datepicker?
// $(this).datepicker();//没反应
// $(this).datepicker({ dateFormat: "yy/mm/dd", changeMonth: true, changeYear: true });//没反应
// $(this).datepicker("option", $.datepicker.regional["zh-CN"]);//没反应
});
newAdd.find("input[xtype='date']").datepicker();//没反应
newAdd.find("input[xtype='date']").datepicker({ dateFormat: "yy/mm/dd", changeMonth: true, changeYear: true });//没反应
newAdd.find("input[xtype='date']").datepicker("option", $.datepicker.regional["zh-CN"]);//没反应
});
});改成这样试试。
应该是 datepickeer 什么地方有问题吧!?
代码没什么问题,建议你把alert去掉,换成console.log或者直接不要加这行。
毕竟alert会阻止JS代码运行的。
比如这样——
<button id="btn">add</button>
<script>
$("#btn").click(function () {
$("<div></div>").datepicker().appendTo("body");
});
</script>
看样子你的写法是input上创建datepicker,接着附加元素,这样就有的元素已经有datepicker而有的没有。
你又不加以区别,通通选中,全都绑定click事件,全都使用datepicker。
……总的来说你写的太混乱了……
$("input[xtype='date']").live("focus", function () {
$(this).datepicker({ dateFormat: "yy-mm-dd", changeMonth: true, changeYear: true });
});