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

192
Views
Cómo hacer que el script se ejecute una vez que se carga el primer script

Estoy tratando de hacer un marco web y una característica será una herramienta de administración de estado de clave-valor. Necesito que la segunda etiqueta <script> se ejecute solo después de que se cargue ./script.js .
índice.html:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="./framework.js"></script> </head> <body> <p f-text="name"></p> <script> Framework.store('name', 'Joe'); </script> </body> </html>

framework.js:

 document.querySelectorAll('*').forEach((element) => { if (element.hasAttribute('f-text')) { const textValue = element.getAttribute('f-text'); const key = window.fStore.find((x) => x.key === textValue); element.innerHTML = key.value; } }); window.Framework = { store: (key, value?) => { if (!value) { const foundKey = window.fStore.find((x) => x.key === key); return foundKey.value; } window.fStore = [...window.fStore, { key: key, value: value }]; } }

Error:

 SyntaxError: Unexpected token ')' at /framework.js:12:22 ReferenceError: Framework is not defined at /:12:5
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe esperar a que se cargue su script, puede usar esto

 window.addEventListener('load', function() { Framework.store('name', 'Joe'); })
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!