我们可以重写一个方法

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

最新文章

  1. mac 无法识别seagate硬盘、无法向其写入文件
  2. ListAdapter列表适配器
  3. 补充ICache
  4. java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别
  5. Python之编写函数
  6. WEB 安全之 SQL注入<一> 盲注
  7. ubuntu添加自定义vga输出分辨率
  8. C# 读取指定URL的内容
  9. lintcode:在O(1)时间复杂度删除链表节点
  10. 关于ASIHTTPRequest连续请求,并发连续,间隔时间很小崩溃问题
  11. 转:100个高质量Java开发者博客
  12. python 网络爬虫(二) BFS不断抓URL并放到文件中
  13. Inno Setup connection to the database and create
  14. LeetCode 62. Unique Paths(所有不同的路径)
  15. 栈详解及java实现
  16. 「POI2011 R2 Day2」Tree Rotations【线段树合并】
  17. react与fetch
  18. C#遍历菜单项
  19. PAT 1042 Shuffling Machine[难]
  20. 【LOJ】#2674. 「NOI2012」美食节

热门文章

  1. Go语言核心36讲(Go语言实战与应用十九)--学习笔记
  2. Codeforces 516E - Drazil and His Happy Friends(同余最短路)
  3. Codeforces 1483F - Exam(AC 自动机)
  4. Codeforces Round #717 (Div.2) 题解
  5. base64和图片转换
  6. C++ and OO Num. Comp. Sci. Eng. - Part 5.
  7. Go知识点大纲
  8. exit(0) exit(1) return() 3个的区别
  9. xmake v2.6.1 发布,使用 Lua5.4 运行时,Rust 和 C++ 混合编译支持
  10. pyqt5的下拉菜单,可以进行输入文字