jquery實現表格文字框淡入更改值後淡出

來源:互聯網
上載者:User

標籤:

html代碼

<table style="border:1px solid blue">
        <tr>
            <th>id</th>
            <th>name</th>
            <th>age</th>
            <th>sex</th>
            <th>操作</th>
        </tr>
        <tr>
            <td class="td1">1</td>
            <td class="td1">珠珠</td>
            <td class="td1">21</td>
            <td class="td1">女</td>
            <td class="td2"></td>
        </tr>
        <tr>
            <td class="td1">2</td>
            <td class="td1">琛琛</td>
            <td class="td1">18</td>
            <td class="td1">男</td>
            <td class="td2"></td>
        </tr>
    </table>

jquery代碼

<script>
        var a;
        $(document).ready(function () {
            $("td[class=‘td1‘]").click(function () {
                var tdlist = $(this).parent().children();//擷取td
                a = "<tr style=‘display:none‘>";
                tdlist.each(function (i) {
                    var text = tdlist.eq(i).text();
                    if (tdlist.eq(i).html().indexOf("input") < 0&&tdlist.eq(i).html().indexOf("button")<0) {
                        if (tdlist.length == (i + 1)) {
                            a+="<td><button>確定</button></td>";
                        }
                        else if (i==0) {
                            a += "<td><input type=‘text‘ readonly=‘true‘ value=‘" + text + "‘></td>";
                        }
                        else {
                            a+="<td><input type=‘text‘ value=‘"+text+"‘></td>";
                        }
                    }
                });
                a += "</tr>";
                $(this).parent().after(a).next().fadeIn("3000");
             });
            $(this).delegate("button", "click", function () {

                var list = $(this).parent().parent().children();//當前td的值
                var li = $(this).parent().parent();//當前tr
                list.each(function (i) {
                    var b = list.eq(i).children().eq(0).val();//當前input的值
                    var shngjitd=li.prev().children();//上一級td
                    if (list.length != (i+1)) {
                         shngjitd.eq(i).text(b);
                        li.fadeOut("3000");
                    }
                    else {
                        list.eq(i).text("");
                    }

                });


            });
      
            });
    </script>

 

jquery實現表格文字框淡入更改值後淡出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.