zoukankan      html  css  js  c++  java
  • JQuery1.72中二个Bug,formhtml()方法与clone()方法的二个Bug进行重写

    //扩展方法$.formhtml,解决firefox中html()方法得不到修改input值后的html代码
    (function ($) {
        var oldHTML = $.fn.html;
        $.fn.formhtml = function () {
            if (arguments.length) return oldHTML.apply(this, arguments);
            $("input,textarea,button", this).each(function () {
                this.setAttribute('value', this.value);
            });
            $(":radio,:checkbox", this).each(function () {
                // im not really even sure you need to do this for "checked"
                // but what the heck, better safe than sorry
                if (this.checked) this.setAttribute('checked', 'checked');
                else this.removeAttribute('checked');
            });
            $("option", this).each(function () {
                // also not sure, but, better safe...
                if (this.selected) this.setAttribute('selected', 'selected');
                else this.removeAttribute('selected');
            });
            return oldHTML.apply(this);
        };

        //optional to override real .html() if you want
        // $.fn.html = $.fn.formhtml;
    })(jQuery);

    //重写clone方法/textarea和select的值clone的时候会丢掉,具体查看http://asialee.iteye.com/blog/1753447
    (function (original) {
        jQuery.fn.clone = function () {
            var result = original.apply(this, arguments),
                my_textareas = this.find('textarea').add(this.filter('textarea')),
                result_textareas = result.find('textarea').add(result.filter('textarea')),
                my_selects = this.find('select').add(this.filter('select')),
                result_selects = result.find('select').add(result.filter('select'));
            for (var i = 0, l = my_textareas.length; i < l; ++i) $(result_textareas[i]).val($(my_textareas[i]).val());
            for (var i = 0, l = my_selects.length; i < l; ++i) result_selects[i].selectedIndex = my_selects[i].selectedIndex;
            return result;
        };
    })(jQuery.fn.clone);

  • 相关阅读:
    带有头结点的链表的基本操作
    转:gdb相关学习
    wareshark网络协议分析之ARP
    wareshark网络协议分析之DHCP
    java多线程(内附实例:窗口售票问题、人和叉子的问题)
    Android深度探索(卷1)HAL与驱动开发 虚拟环境的安装
    source insigt、pc-lint、VS联合使用
    java arrays类学习
    C#函数重载
    (转)Pycharm用鼠标滚轮控制字体大小
  • 原文地址:https://www.cnblogs.com/q149072205/p/3303740.html
Copyright © 2011-2022 走看看