“设置”为 null 或不是对象(jquery ui datepicker)

发布于 2024-10-09 10:31:03 字数 361 浏览 0 评论 0原文

我有一个通过简单模式弹出窗口显示的表单,其中一个表单元素是 jquery ui 日期选择器。如果您打开表单,选择一个日期,关闭模式,然后再次打开表单并尝试选择一个日期,我会收到帖子标题中的 JavaScript 错误 (IE8)。由于我目前正在工作,所以我还没有在其他浏览器上测试过它,但我需要在 IE8 上运行它。

引发此错误的代码示例可以在 http://jsbin.com/uzewi4/10

我不太擅长 javascript,但我假设 simplemodal 正在破坏或在关闭模式时做一些奇怪的事情,这会导致日期选择器中断。我有什么想法可以解决这个问题吗?

I've got a form that gets shown via a simplemodal popup and one of the form elements is a jquery ui datepicker. If you open the form, choose a date, close the modal, then open the form again and try and choose a date I get a javascript error (IE8) that's in the title of the post. I haven't tested it on other browsers as I am in work at the moment, but I need this working on IE8.

An example of the code that throws this error can be found at http://jsbin.com/uzewi4/10

I'm not very good at javascript, but I'm assuming simplemodal is destroying or doing something weird when you close the modal, which causes the datepicker to break. Any ideas how I can fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恏ㄋ傷疤忘ㄋ疼 2024-10-16 10:31:03

这是简单模态。来自文档

克隆和元素删除

默认情况下,SimpleModal 将克隆您传入的数据元素。当对话框关闭时,克隆的、未更改的数据元素将重新插入到 DOM 的原始位置。如果 persist 选项为 true,SimpleModal 将“重新插入”原始元素,且更改完好无损。

所以它会克隆元素,然后用克隆替换它们。显然 DatePicker 并不期望这种情况发生(可以理解)。

非常奇怪的行为,但是添加 persist: true 使您的示例有效:

$('.start').click(function (e) {
  $('#startform').modal({
    opacity:50,
    overlayCss: {backgroundColor:"#000"},
    overlayClose:true,
    persist: true             // <== This is the new bit
    });
  return false;
});  

http://jsbin. com/uzewi4/11

题外话:FWIW,jQuery UI 本身有一个非常好的 对话机制,包括模态...

It's SimpleModal. From the docs:

CLONING AND ELEMENT REMOVAL

By default, SimpleModal will clone the data element that you pass in. When the dialog is closed, the cloned, unchanged, data element will be re-inserted into DOM in its original place. If the persist option is true, SimpleModal will "re-insert" the original element, with changes intact.

So it's cloning the elements, and then replacing them with clones. Clearly DatePicker isn't expecting that to happen (understandably).

Very odd behavior, but adding persist: true makes your example work:

$('.start').click(function (e) {
  $('#startform').modal({
    opacity:50,
    overlayCss: {backgroundColor:"#000"},
    overlayClose:true,
    persist: true             // <== This is the new bit
    });
  return false;
});  

http://jsbin.com/uzewi4/11

Off-topic: FWIW, jQuery UI itself has a perfectly nice dialog mechanism, including modality...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文