jsp中一行多條資料情況

來源:互聯網
上載者:User

標籤:style   blog   http   ar   io   color   sp   strong   on   

1.實現效果:點擊新增會在之前文字框後一直新增文字框並且保留新增的圖片
:

2.jsp代碼:

<table class="Business_Table">        <tr>            <td class="TableLabel_Left TableLabel_Tip">                <span style="float:left" class="bold">附著高度</span>            </td>        </tr>    </table>    <div style="display: none" id="fzgdTableTbodyTemp"><!--主要是為了po對象欄位及顯示欄位問題 -->        <ww:hidden name="fzgdList[].id" id="fzgdList[]_id" />        <ww:hidden name="fzgdList[].wxyqkid" id="fzgdList[]_wxyqkid" />        <ww:hidden name="fzgdList[].lsbz" id="fzgdList[]_lsbz" />        <ww:hidden name="fzgdList[].gcid" id="fzgdList[]_gcid"/>        <ww:hidden name="fzgdList[].gccode" id="fzgdList[]_gccode"/>        <ww:hidden name="fzgdList[].cjsj" id="fzgdList[]_cjsj"/>        <div style="display: none"><ww:checkbox name="RP_VISIBLE"  theme="simple" /></div>        <div style="background-color: #00bfff;" style="width: 100%;text-align:center;">第()道</div>        <div>            <ww:textfield name="fzgdList[].fzgd" id="fzgdList[]_fzgd" theme="simple"                          subNum="2" precision="2" validType="length[1,6]"    cssClass="txtBox easyui-numberbox" />        </div>    </div>    <div style="display: none" id="fzgdTableTbodyImg"><!--主要是為了圖片的問題 -->        <td class="Page_TableText_Center"  style="width: 20%"  onmousemove="this.bgColor=‘yellow‘" onmouseout="this.bgColor=‘#FFFFFF‘">            <img src="/skin/silver/images/add.gif" alt="" onclick="addFzgd(‘fzgdTableTbody‘)"/>            <div style="display: none"><ww:checkbox name="RP_VISIBLE"  theme="simple" /></div>        </td>    </div>    <table class="Page_Table_Common div_page_margin">        <ww:if test="fzgdList != null">            <tbody id="fzgdTableTbody">            <ww:iterator value="fzgdList" status="rowstatus" id="it"><!-- 因為一行顯示5條資料,判斷是否新增tr-->                <ww:if test="#rowstatus.index%5==0">                    <tr style="height: 55px;">                </ww:if>                <td class="Page_TableText_Center" onmousemove="this.bgColor=‘yellow‘" onmouseout="this.bgColor=‘#FFFFFF‘"                    style="width: 20%;" >                    <ww:hidden name="fzgdList[${rowstatus.index}].id" id="fzgdList[${rowstatus.index}]_id" />                    <ww:hidden name="fzgdList[${rowstatus.index}].wxyqkid" id="fzgdList[${rowstatus.index}]_wxyqkid" />                    <ww:hidden name="fzgdList[${rowstatus.index}].lsbz" id="fzgdList[${rowstatus.index}]_lsbz" />                    <ww:hidden name="fzgdList[${rowstatus.index}].gcid" id="fzgdList[${rowstatus.index}]_gcid"/>                    <ww:hidden name="fzgdList[${rowstatus.index}].gccode" id="fzgdList[${rowstatus.index}]_gccode"/>                    <ww:hidden name="fzgdList[${rowstatus.index}].cjsj" id="fzgdList[${rowstatus.index}]_cjsj"/>                    <div style="display: none"><ww:checkbox name="RP_VISIBLE"  theme="simple" /></div>                    <div style="background-color: #00bfff;" style="width: 100%;text-align:center;">第(${rowstatus.index+1})道</div>                    <div>                        <ww:textfield name="fzgdList[${rowstatus.index}].fzgd" id="fzgdList[${rowstatus.index}]_fzgd" theme="simple"                                      subNum="2" precision="2" validType="length[1,6]"    cssClass="txtBox easyui-numberbox" />                    </div>                </td>                <ww:if test="#rowstatus.last">                    <ww:if test="#rowstatus.count%5 != 0">                            <td class="Page_TableText_Center"  style="width: 20%"                                onmousemove="this.bgColor=‘yellow‘" onmouseout="this.bgColor=‘#FFFFFF‘">                                    <img src="/skin/silver/images/add.gif" alt="" onclick="addFzgd(‘fzgdTableTbody‘)"/>                                    <div style="display: none"><ww:checkbox name="RP_VISIBLE"  theme="simple" /></div>                            </td>                        </tr>                    </ww:if>                    <ww:else>                        </tr>                        <tr style="height: 45px" >                            <td class="Page_TableText_Center"  style="width: 20%"  onmousemove="this.bgColor=‘yellow‘" onmouseout="this.bgColor=‘#FFFFFF‘">                                <img src="/skin/silver/images/add.gif" alt="" onclick="addFzgd(‘fzgdTableTbody‘)"/>                                <div style="display: none"><ww:checkbox name="RP_VISIBLE"  theme="simple" /></div>                            </td>                        </tr>                    </ww:else>                </ww:if>                <ww:elseif test="#rowstatus.count%5 == 0 && #rowstatus.index != 0">                    </tr>                </ww:elseif>            </ww:iterator>            </tbody>        </ww:if>    </table>

 

3.js增加方法:

function addFzgd(tbodyid){        var checkls = document.getElementsByName("RP_VISIBLE").length-2;//標示當前所含有的td個數        var _copy = $("#" + tbodyid + "Temp").html();   //需要添加的html        var addHtml = $("#" + tbodyid + "Img").html();        var imgHtml = $("#" + tbodyid+" tr:last-child td:last-child").html();  //擷取最後一行的最後一個td        if(checkls%5 == 0){ //此時表示如果添加則到下一行            $("#" + tbodyid).html($("#" + tbodyid).html().replace(imgHtml,_copy));            $("#" + tbodyid).append("<tr style=‘height: 55px‘>"+addHtml+"</tr>");        }  else{  //在本行添加            $("#" + tbodyid).html($("#" + tbodyid).html().replace(imgHtml,_copy));//將添加圖片替換,然後新增一行            $("#" + tbodyid+" tr:last-child").append(addHtml);        }        //重設對象List下標        var listName = "";        if (tbodyid.indexOf("fzgd") != -1) {            listName = "fzgdList";        }        $("#" + tbodyid + " tr td").each(function (i) {            $(this).find("input,div").each(function () {                var fieldname = $(this).attr("name");                if (fieldname != undefined) {                    fieldname = fieldname.split("].")[1]                    $(this).attr("name", listName + "[" + i + "]." + fieldname);                    $(this).attr("id", listName + "[" + i + "]_" +fieldname);                } else{                    if($(this).text().indexOf("第(") != -1){                        $(this).text("第("+(i+1)+")道");                    }                }            });        });    }

4.需要做的配置:在XxxAction的同級目錄下建立XxxAction-conversion.properties,檔案內容為

Element_fzgdList=com.xx.xx.xx.xx.po.TpzFzgdCreateIfNull_fzgdList=true

jsp中一行多條資料情況

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.