Click on the cell to edit the text in the cell How to make _javascript tips

Source: Internet
Author: User
How to implement through JavaScript when you click the corresponding cell, the text in the cell becomes editable input or select, leaving the cell and then the text in the cell is the modified text.
I do this by clicking the cell into input, not knowing how to restore the text state after the other cells, and how to return the value modified after the input. Is there a better way to achieve this effect.
<script language= "JavaScript" > Window.attachevent ("onload", gettable); function GetTable () {for (i=0; i<tbl.cells.length; i++) {var cell = Tbl.cells[i]; Cell.attachevent ("onmousedown", gettexttoinput); } gettexttoinput = function (evt) {var input; var html evt = (evt)? EVT: ((window.event)? Window.event: "") if (evt) {var cell = (evt.target)? Evt.target:evt.srcElement; For (i=0 i<tbl.cells.length; i++) {if (tbl.cells[i] = = cell) {html = ' <input type= ' text "Value=" ' + Tbl.cells[i].innertext + ' "> ' tbl.cells[i].innerhtml = html; }} </script> <table border= "1" cellpadding= "0" cellspacing= "0" id= "tbl" > <tr> &L t;td>123</td> <td>456</td> </tr> <tr> <td>abc</td> <td>efg</ Td> </tr> </table>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

2,
<script language= "JavaScript" > Window.attachevent ("onload", gettable); function GetTable () {for (i=0; i<tbl.cells.length; i++) {var cell = Tbl.cells[i]; Cell.attachevent ("onmousedown", gettexttoinput); } gettexttoinput = function (evt) {var input; var html evt = (evt)? EVT: ((window.event)? Window.event: "") if (evt) {var cell = (evt.target)? Evt.target:evt.srcElement; For (i=0 i<tbl.cells.length; i++) {if (tbl.cells[i] = = cell) {html = ' <input type= ' text "id=" input ' +i+ ' "value=" ' + Tbl.cells[i].innertext + ' "onblur=" this.parentnode.innerhtml=this.value; "onkeydown=" if ( window.event.keycode==13) {this.parentnode.innerhtml=this.value;} " > ' tbl.cells[i].innerhtml = html; Window.settimeout (' document.getElementById ("input ' +i+ '). focus (); ', 300; }} </script> <table border= "1" cellpadding= "0" cellspacing= "0" id= "tbl" > <tr> <td>123</td> <td>456</td> </tr> <tr> <t d>abc</td> <td>efg</td> </tr> </table>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.