Soy muy nuevo en javascript. Solo he estado trabajando con él durante una semana. He estado tratando de actualizar la columna de la tabla html con un valor de 0 a un número aleatorio generado por javascript. Esto es lo que he intentado hasta ahora, con la función "reproduce", pero no produce ningún resultado. ¿Qué errores tengo y qué me falta en mi código? Cualquier ayuda sería muy apreciada.
<table class="content-table"> <tbody id="groupH" onload="plays()"> <tr> <td>4</td> <td>Poland</td> <td>3</td> <td>1</td> <td id='updateDraw'>0</td> <td>2</td> <td>2</td> <td>5</td> <td>-3</td> <td>3</td> </tr> </tbody> </table> <!-- Update points table as page refreshes--> <script> function plays(){ document.getElementById("updateDraw").innerHTML = Math.floor(Math.random()* 10); } </script>No hay onload en un elemento tbody . Esto se plantea cuando se carga la ventana:
function plays() { document.getElementById("updateDraw").innerHTML = Math.floor(Math.random() * 10); } window.addEventListener("load", plays); <table class="content-table"> <tbody id="groupH"> <tr> <td>4</td> <td>Poland</td> <td>3</td> <td>1</td> <td id='updateDraw'>0</td> <td>2</td> <td>2</td> <td>5</td> <td>-3</td> <td>3</td> </tr> </tbody> </table>Usted puede comprobarlo
<table class="content-table"> <tbody id="groupH"> <tr> <td>4</td> <td>Poland</td> <td>3</td> <td>1</td> <td id='updateDraw'>0</td> <td>2</td> <td>2</td> <td>5</td> <td>-3</td> <td>3</td> </tr> </tbody> </table> <!-- Update points table as page refreshes--> <script> function plays(){ document.getElementById("updateDraw").innerHTML = Math.floor(Math.random() * 10); } window.onload = function () { plays(); } </script>Otra forma es adjuntar la llamada onload a la etiqueta <body> :
<body onload="plays()"> <table class="content-table"> <tbody id="groupH"> <tr> <td>4</td> <td>Poland</td> <td>3</td> <td>1</td> <td id='updateDraw'>0</td> <td>2</td> <td>2</td> <td>5</td> <td>-3</td> <td>3</td> </tr> </tbody> </table> <!-- Update points table as page refreshes--> <script> function plays() { document.getElementById("updateDraw").innerHTML = Math.floor(Math.random() * 10); } </script> </body>