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());
                }
  • 相关阅读:
    Android Studio 快捷键
    维基百科地址(应该是吧)
    Freeswitch常見問題解決辦法
    配置SIP网关拨打外部电话
    Freeswitch连接SIP软电话
    CentOS6.5安装freeswitch以及啟動
    hdu 4292: Food(Dinic + 链式前向星)
    hdu 2709:Sumsets(递推)
    hdu 2577:How to Type(动态规划)
    hdu 2955:Robberies(01背包)
  • 原文地址:https://www.cnblogs.com/lidedong/p/14607314.html
Copyright © 2011-2022 走看看