凌的博客

您现在的位置是: 首页 > 前端学习 > JQuery > 

JQuery

js 打印 html input没有值

2022-06-05 JQuery 1107
//重新赋值
(function ($) {
        var oldHTML = $.fn.html;
        $.fn.formhtml = function () {
            if (arguments.length) return oldHTML.apply(this, arguments);
            $("input,button", this).each(function () {
                this.setAttribute('value', this.value);
            });
            $("textarea", this).each(function () {
                this.setAttribute('value', this.value);
                this.innerHTML= 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);

//调用
var html=$("#id").formhtml();


文章评论

0条评论