jQuery UI触发器日期拾取器
jQuery UI trigger datepicker
我有一个span/date元素,如下图
<span class="editableDateTxt">06/10/2014</span>
现在点击这个,我想显示内联可编辑的日期弹出(或jQuery UI日期picker)
当视图被渲染时,我有;
var self = this,
$el = $(self.el);
$el.find(".datePicker" ).datepicker();
对于editabledatetext的click,我有;
$(document).on("click",".editableDateTxt", function () {
var input = $('<input />', {'type': 'text', 'class':'datePicker hasDatepicker', 'value': $(this).html()});
$(this).parent().append(input);
$(this).remove();
input.focus();
});
但是日期选择器没有被触发(我看不到UI上的日期选择器)
我做错了什么吗
因为在渲染视图时没有类为datePicker
的元素,只有在单击editableDateTxt
元素时才会添加。所以你的$el.find(".datePicker" ).datepicker()
语句没有任何意义。
$(document).on("click", ".editableDateTxt", function () {
var input = $('<input />', {
'type': 'text',
'class': 'datePicker',
'value': $(this).html()
});
$(this).after(input);
$(this).remove();
//create a datepicker and show it
input.datepicker({}).datepicker('show')
//input.focus();
});
演示:小提琴
使用这个代码片段。
$(document).on("click", ".editableDateTxt", function () {
var input = $('<input />', {
'type': 'text',
'class': 'datePicker',
'value': $(this).html()
});
$(this).parent().append(input);
$(this).remove();
//create a datepicker and show it
$('.datePicker').datepicker().datepicker('show'); //use this to show instead input.focus()
});
工作演示小提琴
- 不需要手动添加
hasDatepicker
类。日期picker插件将它添加到元素中。 - ,动态生成
<input>
元素;没有在DOM上准备好class="datePicker"
的元素。您需要在添加元素后显式调用.datePicker()
。
下面是在底部显示的工作演示中工作的代码:
$(document).on("click",".editableDateTxt", function () {
var input = $('<input />', {'type': 'text','value': $(this).text()});
$(this).parent().append(input);
$(this).remove();
input.datepicker();
input.datepicker('show');
});
Working jsfiddle Demo
相关文章:
- ui网格日期单元格过滤器,过滤日期格式导致显示错误的日期
- JQuery UI日期选择器:在选择出发日期时自动弹出返回日期
- Angular UI启动日期选择器问题
- 在日期更改后更新Angular UI引导程序日期选择器选项
- Jquery UI日期选择器不关注输入
- angular ui boostrap日期选择器显示年份第一
- Jquery UI日期选择器没有'单击链接时不会再次显示
- 从Function触发JQuery UI日期选择器,并将日期存储到变量中
- jQuery UI DatePicker-禁用除每月第一天和第15天以外的所有日期
- Onsen UI在点击时显示一个日期选择器
- 将 jQuery UI 日期选择器与异步 AJAX 请求一起使用
- 如何在 Angular UI 日期选择器中格式化行和月份名称
- 如何在 jQuery 日期选择器 UI 中阻止多个日期范围
- 为什么引导 UI 在加载时不显示正确的日期格式
- 在JQuery UI日期选择器中禁用当前日期之前的日期
- Javascript日期-指定传入日期格式(jQuery UI DateTimepicker)
- 正在禁用jQuery UI日期选取器日期
- 正在将Jquery UI日期选择器链接到DropDownlist
- 从日期选择器中获取默认格式的日期,并在jquery UI中转换为其他格式
- 如何启用由日期选择器 ui 附加的输入?(JQuery 插件)