How to retrieve value of input type in a dynamic table

前端 未结 6 571
迷失自我
迷失自我 2020-12-11 00:29



        
6条回答
  •  粉色の甜心
    2020-12-11 01:05

    For future readers, here's a full demo snippet with it working... (based on the accepted answer)

    Also setup a second function to display the value of the second cell if clicked - to show how to access the value from the next cell.

    function showText(tableID) {
         var tbl = document.getElementById(tableID);
         var rCount = tbl.rows.length;
         try {
             alert(tbl.rows[rCount-1].cells[0].children[0].value);
    
         } catch (e) {
             alert(e);
         }
    
     }
     
     function showFont(tableID) {
         var tbl = document.getElementById(tableID);
         var rCount = tbl.rows.length;
         try {
             alert(tbl.rows[rCount-1].cells[1].children[0].value); // Note changed to cell[1] for the next cell
    
         } catch (e) {
             alert(e);
         }
    
     }
    Text Font Size Color

提交回复
热议问题