简体   繁体   中英

JavaScript how to add data to a variable

I have

var  table = "<tr><td><input type='hidden' class='hid_id' value='"+id+"' /> "+id+
"</td><td>"+document.getElementById("name_"+id).value+
"</td><td>"+document.getElementById("price_"+id).value+
"</td><td><input type='text' id='qua_"+id+
"' value='1' disabled='disabled' /></td><td><button>more</button></td></tr>";

to add to table when user click Addbutton

  <table id="tbForm1"  border="1">
         <tbody>
         </tbody>
  </table>

But I want store it (var table ) and assign to other one variable and all row when user click add. How I can ?

Edit I don't know syntax of JavaScript but if it's PHP , I mean:

  $ba .= 'a';
  if(click=='add'){
   $ba .='b';
  }
  echo $ba; //outup ab

As Vohuman mentioned use that function to create dynamic row with an Id and use below to add that row to another table.

var x =document.getElementById("tbForm1").getElementsByTagName('tbody');
x.innerHTML = generateRow(id);

Also refer to this to add subsequent rows

How to insert row in HTML table body in javascript?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM