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

111
Views
¿Manejar las clases JS con declaraciones de importación en el archivo html?

tengo 3 archivos

  1. Conexiones.js
  2. Principal.html.
  3. ScriptFile.js

Estoy copiando solo una pequeña parte del código aquí.

Connection.js tiene una clase

 import {net} from 'net'; export class connect { Testfunction() {return "something"} }

main.html tiene una función

 <html> <head> <script src= 'Connections.js'></script> <script src= 'ScriptFile.js'></script> </head> <body> <p id="demo" onclick="myFunction()">Click me to change my text color.</p> </body> </html>

ScriptFile.js

 import { connect } from "./Connections.js"; const ObjConnect = new connect() function myFunction() { document.getElementById("demo").innerHTML = ObjConnect.Testfunction(); }

¿Cómo hago que el "texto" en mi archivo html cambie a "algo" cuando hago clic en él?

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

0

Primero tiene un error tipográfico en el nombre del archivo. Es Conexión, no Conexiones en main.js

Caso 1. utilizando el módulo

  • principal.html
 <html> <head> <script type="module" src="Connection.js"></script> <script type="module" src="ScriptFile.js"></script> </head> <body> <p id="demo">Click me to change my text color.</p> </body> </html>
  • ScriptFile.js
 import { connect } from './Connection.js'; const ObjConnect = new connect(); function myFunction() { document.getElementById('demo').innerHTML = ObjConnect.Testfunction(); } document.getElementById('demo').addEventListener('click', myFunction);

Caso2. usando secuencia de comandos

  • principal.html
 <html> <head> <script src="Connection.js"></script> <script src="ScriptFile.js"></script> </head> <body> <p id="demo" onclick="myFunction()">Click me to change my text color.</p> </body> </html>
  • Conexión.js
 class connect { Testfunction() { return 'something'; } }
  • ScripFile.js
 const ObjConnect = new connect(); function myFunction() { document.getElementById('demo').innerHTML = ObjConnect.Testfunction(); }
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!