如何*完全*删除 jQuery UI 日期选择器? [英] How do I *completely* remove a jQuery UI datepicker?

查看:19
本文介绍了如何*完全*删除 jQuery UI 日期选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期文本字段,我希望只有时附加一个 DatePicker,因为我有一些自己的文本处理脚本来处理部分日期字符串.然而,调用 .remove 或 .destroy 会在输入字段上留下文本格式化行为,这会将我的8"字符串转换为8/18/2010".更糟糕的是,如果我开始删除,它会坚定地假设,一旦我到达8/18/20",我实际上想要8/18/2020".

I've got a date text field I wish to only sometimes attach a DatePicker to, because I have some of my own text-handling scripts which handle partial date strings. Calling .remove or .destroy leaves text formatting behavior on the input field, however, which converts my "8" string into a "8/18/2010". Even worse, if I start deleting, it steadfastly assumes that, once I reach "8/18/20", I actually wanted "8/18/2020".

从我的页面中完全删除日期选择器的最佳方法是什么?如果它始终完全忽略我输入的文本,我也可以使用它,但在这种情况下,我更希望它出现在双击/图像作为按钮上,但并非总是如此.

What would be the best way to completely, entirely, make-it-like-it-never-was remove the datepicker from my page? I can also use it if it just ignores text I enter entirely at all times, though in that case I'd prefer it to appear on a double-click / an image-as-button, not always.

这一切都在 jqGrid 中,其中选择器"是日期列上的文本框:

this is all within a jqGrid, where 'selector' is a text box on a date column:

function showPicker(selector) {
    $(selector).datepicker({
        onClose: function() {
            $(selector).datepicker('remove'); 
            // or 'destroy' or $('.datepicker').remove(); or $(this).datepick('remove');
        }
    });
}

这可以防止它回来,但不能操纵我的文本字段.没有其他代码(我知道)正在操纵该字段的内容,只是 jqGrid 监视输入键以发送数据.查看页面生成的代码,datepicker div 甚至还在底部.

This prevents it from coming back, but not from manipulating my text field. No other code (that I'm aware of) is manipulating that field's contents, just jqGrid watching for the enter-key to send the data. Looking at the page's generated code, the datepicker div is even still at the bottom.

edit2:如果我这样做,我会得到完全相同的行为:

edit2: I get the exact same behavior if I do this:

<html>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"  />
<script type="text/javascript">
$(document).ready( function(){
 $("#pickle").datepicker({
  onClose: function(){
   $(this).datepicker('remove');
  }
 });
});
</script>
<input type="text" id="pickle" />
</body>
</html>

这会导致与我所看到的行为相同的行为,但将其更改为销毁"在此处有效,但在我的页面上无效.奇怪.

That causes identical behavior to what I'm seeing, but changing it to 'destroy' works here but not on my page. Odd.

推荐答案

这完全删除了 .datepicker:

$( selector ).datepicker( "destroy" );
$( selector ).removeClass("hasDatepicker").removeAttr('id');

文档:
https://api.jqueryui.com/datepicker/#method-destroy
还请阅读下面的评论

Documentation:
https://api.jqueryui.com/datepicker/#method-destroy
also read the comments below

这篇关于如何*完全*删除 jQuery UI 日期选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆