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才可以)
  • 相关阅读:
    在排序数组中查找元素
    搜索旋转排序数组
    下一个排列
    括号生成(回溯法)
    PHP之表单
    PHP之超级全局变量
    PHP之数组
    PHP之字符串
    PHP之常量
    PHP之echo/print
  • 原文地址:https://www.cnblogs.com/pxblog/p/15368191.html
Copyright © 2011-2022 走看看