zoukankan      html  css  js  c++  java
  • 改写.html()获取修改后新修改后的Html-----Js

    目的:改写Jquery中的.Html()方法为新的.formhtml()

    功能:将修改的html也复制(原来的.html()只是复制页面中显示的html,不能获取修改以后的html)

    (function ($) {
        var oldHTML = $.fn.html;
        $.fn.formhtml = function () {
            if (arguments.length) return oldHTML.apply(this, arguments);
            $(this).each(function () {
                if (this.type == "input" || this.type == "textarea" || this.type == "button") {
                    this.setAttribute('value', this.value);
                }
                else if (this.type == "radio" || this.type == "checkbox") {
                    if (this.checked) this.setAttribute('checked', 'checked');
                    else this.removeAttribute('checked');
                }
                else if (this.type == "option") {
                    if (this.selected) this.setAttribute('selected', 'selected');
                    else this.removeAttribute('selected');
                }
    
    
                $("input,button", this).each(function () {
                    this.setAttribute('value', this.value);
                });
                $("textarea", this).each(function () {
                    $(this).html(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);
        };
    })(jQuery);
  • 相关阅读:
    CDZSC_2015寒假新人(4)——搜索 A
    第一次组队赛---2010年全国大学生程序设计邀请赛(福州)L
    ZSC新生赛 沼跃鱼早已看穿了一切
    ZSC新生赛 聪明的员工
    CDZSC_2015寒假新人(1)——基础 I
    Linux 系统时间和硬件时间
    Python 深浅复制
    Python 函数内省
    Python 函数参数
    Python 可调用对象
  • 原文地址:https://www.cnblogs.com/KrystalNa/p/4409014.html
Copyright © 2011-2022 走看看