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

436
Views
La carga de la función HTML onClick node js 'requiere' otro módulo en la función onClick no funciona

Tengo un código como:

 <!DOCTYPE html> <html> <body> <h1>HTML DOM Events</h1> <h2>The onclick Event</h2> <p>The onclick event triggers a function when an element is clicked on.</p> <p>Click to trigger a function that will output "Hello World":</p> <button onclick="myFunction()">Click me</button> <p id="demo"></p> <script> function myFunction() { const os = require('os') let hostName = os.hostname() alert(hostName); document.getElementById("demo").innerHTML = "Hello World"; } </script> </body> </html>

El código funciona cuando elimino:

 const os = require('os') hostName = os.hostname() alert(hostName);

Sin embargo, necesito cargar un módulo en esta función que se usa para el evento onClick.

Tenga en cuenta que soy un novato en javascript. Cualquier y toda ayuda / orientación será muy apreciada.

Gracias.

ACTUALIZAR:

para aquellos que vienen a esta página, verifique: ¿Se requiere estilo de nodo para javascript en el navegador?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 const button = document.getElementById('btn'); const demo = document.getElementById('demo'); button.onclick = function() { demo.innerHTML = 'Hello World'; };
 <button id="btn" >Click me</button> <p id="demo"> </p>

Si desea cargar un módulo, debe mostrar parte de su código node.js, ya que no vemos cómo se ve y qué desea representar.

Sugiero leer la documentación de Node.js y EJS.

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!