zoukankan      html  css  js  c++  java
  • JS使用html()获取html代码获取不到input、textarea控件填写的值

    我们可以重写一个方法

    (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();
    -----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------ (蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)
  • 相关阅读:
    tomcat 乱码问题
    mongo获取lbs数据
    sping mvc+uploadify 上传文件大小控制3部曲
    jstack 查看线程状态
    nginx 限流配置
    查找占用CPU高线程
    redis sentinel无法启动问题
    GC垃圾回收机制
    ASP.NET 生命周期
    Javascript验证手机号码正则表达式
  • 原文地址:https://www.cnblogs.com/pxblog/p/15368191.html
Copyright © 2011-2022 走看看