zoukankan      html  css  js  c++  java
  • jq拷贝表单$("#searchForm").clone(true),无法将select2数据value拷贝的问题

    实现导出功能时,需要整合查询条件,需要将查询的列表复制一份,生成一个新的表单,默认action提交信息,代码如下:

    function exportData() {
            try {
                var exportForm = $("#searchForm").clone(true).attr("id", "exportData");
                var select = $("#searchForm").find('select');
                var selectRes = $(exportForm).find('select');
                for (var i = 0; i <select.length ; i++) {
                    $(selectRes[i]).val($(select[i]).val());
                }
                // var exportForm = $("#searchForm").clone(true).attr("id", "exportData");
                exportForm.attr("action", "${ctx}/cop/coe/exportData");
                exportForm.unbind();
                $(document.body).append(exportForm);
                exportForm.submit();
            } catch (e) {
                console.log(e);
            } finally {
                exportForm.remove();
            }
        }

    在改造的过程中,发现

    $("#searchForm").clone(true)无法select的value拷贝到新的表单对象中,但是属性已经拷贝进来了。通过打印数据找到了解决方法
    遍历原始表单组件,找到所有的select组件,获取到value之后再将数据赋值到新的拷贝对象中,这样就解决了
    $("#searchForm").clone(true)带来的弊端。
    var select = $("#searchForm").find('select');
                var selectRes = $(exportForm).find('select');
                for (var i = 0; i <select.length ; i++) {
                    $(selectRes[i]).val($(select[i]).val());
                }
  • 相关阅读:
    联表查询用on和where的区别
    了解触发器
    QUIC协议,了解
    SQL Mode
    redis持久化
    Kali Linux渗透测试实战 1.2 环境安装及初始化
    电容降压
    单火取电
    大整数的因子
    最大公约数
  • 原文地址:https://www.cnblogs.com/lidedong/p/14607314.html
Copyright © 2011-2022 走看看