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);

  • 相关阅读:
    网站添加share.js一键分享
    tp5利用phpExecl导出
    项目可能需要用到的公共方法
    拖拽文件上传
    推荐Alipay和Watch 支付 yansongda SDK
    在画布中添加二维码加文字 和 压缩多图片到一个压缩包中
    redis使用
    微信公众号网页授权登录
    第三方登入及详细操作
    订单并发问题及解决方案
  • 原文地址:https://www.cnblogs.com/q149072205/p/3303740.html
Copyright © 2011-2022 走看看