带有 jquery ui datepicker 的 Knockout.js 适用于除 IE 之外的任何地方 [英] Knockout.js with jquery ui datepicker works everywhere except IE

查看:15
本文介绍了带有 jquery ui datepicker 的 Knockout.js 适用于除 IE 之外的任何地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个knockout.js 模板脚本来创建一个可以复制和删除的表单.可以在此处找到小提琴.

I used a knockout.js templatescript to create a form that can be duplicated and deleted. The fiddle can be found here.

我在 SE 的帮助下编辑了脚本以添加 jquery-ui 日期选择器.可以在[此处][2]找到小提琴的简短版本.到目前为止一切顺利,但在测试时我发现除了 IExplorer(各种版本)之外,所有浏览器都可以正常工作.

I editted the script with a litle help from SE to add a jquery-ui datepicker. The short version of the fiddle can be found [here][2]. So far so good, but when testing i found out that everything works in any browser, except for IExplorer (various versions).

问题出在这个特定部分,但我不知道在哪里.

The problem is in this specific part, but i have no clue where.

script type='text/javascript'>//<![CDATA[ 
ko.bindingHandlers.datepicker = {
    init: function (element, valueAccessor, allBindingsAccessor) {
        var options = allBindingsAccessor().datepickerOptions || {};

        console.log("datepicker");                        
        $(element).datepicker(options);

        //handle the field changing
        ko.utils.registerEventHandler(element, "change", function () {
            var observable = valueAccessor();
            observable($(element).datepicker("getDate"));
        });

        //handle disposal (if KO removes by the template binding)
        ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
            $(element).datepicker("destroy");
        });

    }
};

现在我们也开始了.当您在框外单击时,日期选择器不会关闭.这发生在任何浏览器中.

Also now we're at it. The datepicker doesn't close when you click outside the box. This happens in any browser.

其他问题

  1. 我使用这个(和许多其他的)来自动更正一个字段.在这种情况下,输入大写.这在第一种形式上效果很好.但不是在任何重复的表格上.

  1. I use this (and many others) to autocorrect a field. In this case uppercase the input. This works excellent on the first form. But not on any duplicate forms.

$(".hoofdletters").keyup(function(e){$(".hoofdletters").val(($(".hoofdletters").val()).toUpperCase());});

$(".hoofdletters").keyup(function(e) { $(".hoofdletters").val(($(".hoofdletters").val()).toUpperCase()); });

当我使用 uniqueName: true 时,每个字段(也是重复的表单)都会得到验证.但是我的 $_POST 名字都被重命名了.我想要原始字段名称,例如 year[] 而不是 ko_unique_1.删除 uniqueName 时有效,但重复的表单不再验证.

When i use uniqueName: true, every field (also duplicated forms) will get validated. But my $_POST names are all renamed. I would like the originall field names, for example year[] instead of ko_unique_1. Works when removing uniqueName, but then the duplicated forms don't validate anymore.

[2]:http://jsfiddle.net/QUxyy/5/在此处输入代码

推荐答案

  1. 要使代码在 IE 上运行:删除console.log"指令
  2. 要更改日期格式,您可以定义如下绑定:

  1. To make the code work on IE: Remove "console.log" instruction
  2. To change the date format, you can define a binding like this one:

data-bind='datepicker: beschikkingsdatum, datepickerOptions: {dateFormat: "dd/mm/yy"}, uniqueName: true'

data-bind='datepicker: beschikkingsdatum, datepickerOptions: {dateFormat: "dd/mm/yy"}, uniqueName: true'

这篇关于带有 jquery ui datepicker 的 Knockout.js 适用于除 IE 之外的任何地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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