使用JQuery雙擊修改Table中Td

來源:互聯網
上載者:User

標籤:style   blog   http   io   color   os   ar   使用   sp   

<html><head>    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>    <style>        table{            border-collapse:collapse;            border-spacing:0;            margin-right:auto;            margin-left:auto;            width:100%;        }                th,td{            border:1px solid #b5d6e6;            font-size:12px;            font-weight:normal;            vertical-align:middle;            height:20px;            width:25%;        }        th{            text-align:center;            background-color:Gray;        }    </style>    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>    <script>    $(function(){$(‘#tableId‘).on(‘dblclick‘,‘td‘,function(){                //console.info($(this).text());                var oldVal = $(this).text();                var input = "<input type=‘text‘ id=‘tmpId‘ value=‘" + oldVal + "‘ >";                $(this).text(‘‘);                $(this).append(input);                $(‘#tmpId‘).focus();                $(‘#tmpId‘).blur(function(){                    if($(this).val() != ‘‘){                       oldVal = $(this).val();                    }                    //closest:是從當前元素開始,沿Dom樹向上遍曆直到找到已應用選取器的一個匹配為止。                   $(this).closest(‘td‘).text(oldVal);                });            });});</script></head><body><table id="tableId">            <tr><th>head01</th><th>head02</th><th>head03</th><th>head04</th></tr>            <tr><td>head11</td><td>head12</td><td>head13</td><td>head14</td></tr>            <tr><td>head21</td><td>head22</td><td>head23</td><td>head24</td></tr>            <tr><td>head31</td><td>head32</td><td>head33</td><td>head34</td></tr>            <tr><td>head41</td><td>head42</td><td>head43</td><td>head44</td></tr>        </table></body></html>

 

使用JQuery雙擊修改Table中Td

聯繫我們

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