js 打印 html input没有值
2022-06-05 JQuery 1810
//重新赋值 (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)
相关文章
文章评论
-
-
-
0条评论