JS使用html()获取html代码获取不到input、textarea控件填写的值
2024-09-05 18:36:17
我们可以重写一个方法
(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();
最新文章
- mac 无法识别seagate硬盘、无法向其写入文件
- ListAdapter列表适配器
- 补充ICache
- java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别
- Python之编写函数
- WEB 安全之 SQL注入<;一>; 盲注
- ubuntu添加自定义vga输出分辨率
- C# 读取指定URL的内容
- lintcode:在O(1)时间复杂度删除链表节点
- 关于ASIHTTPRequest连续请求,并发连续,间隔时间很小崩溃问题
- 转:100个高质量Java开发者博客
- python 网络爬虫(二) BFS不断抓URL并放到文件中
- Inno Setup connection to the database and create
- LeetCode 62. Unique Paths(所有不同的路径)
- 栈详解及java实现
- 「POI2011 R2 Day2」Tree Rotations【线段树合并】
- react与fetch
- C#遍历菜单项
- PAT 1042 Shuffling Machine[难]
- 【LOJ】#2674. 「NOI2012」美食节
热门文章
- Go语言核心36讲(Go语言实战与应用十九)--学习笔记
- Codeforces 516E - Drazil and His Happy Friends(同余最短路)
- Codeforces 1483F - Exam(AC 自动机)
- Codeforces Round #717 (Div.2) 题解
- base64和图片转换
- C++ and OO Num. Comp. Sci. Eng. - Part 5.
- Go知识点大纲
- exit(0) exit(1) return() 3个的区别
- xmake v2.6.1 发布,使用 Lua5.4 运行时,Rust 和 C++ 混合编译支持
- pyqt5的下拉菜单,可以进行输入文字