Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Agregar botones a la última columna

¿Cómo agregar un botón a mi tabla HTML con JS? La tabla se crea con JS utilizando datos de archivo XML.

He intentado agregar un botón donde se crea la tabla (entre <td></td> ), sin embargo, sin suerte.

 function loadXMLDoc() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if(this.readyState == 4 && this.status == 200) { perDetails(this); } }; xmlhttp.open("GET", "../xml/data.xml", true); xmlhttp.send(); } function perDetails(xml) { var i; var xmlDoc = xml.responseXML; var table =`<tr><th>Title</th><th>Model</th><th>Price(EUR)</th><th>Delivery Time</th> <th>In Stock</th><th>Button Column</th></tr>`; var x = xmlDoc.getElementsByTagName("phones"); console.log(x); // Start to fetch the data by using TagName for (i = 0; i < x.length; i++) { let btn = document.createElement("button"); btn.type = "add"; btn.name = "addBtn"; table += "<tr><td>" + x[i].getElementsByTagName("title")[0] .childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("model")[0] .childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("item_price")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("delivery_text")[0].childNodes[0].nodeValue + "</td><td>" + x[i].getElementsByTagName("stock")[0].childNodes[0].nodeValue + "</td></tr>"; // Print the xml data in table form document.getElementById("table").innerHTML = table; } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

De acuerdo con el encabezado de su tabla, debe agregar su botón aquí:

 x[i].getElementsByTagName("stock")[0].childNodes[0].nodeValue + "</td>" + "<td><button type='button'>click me</button></td></tr>";
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!