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

357
Views
Incrustar scripts en botones html

Entonces, soy un programador principiante y pensé que podría hacer algo corto y divertido. Hice un programa corto en unos 5 minutos, pero me encontré con un problema que no puedo resolver, cómo hacer un botón que ejecute dicho script cuando se presiona (por ejemplo, genera una alerta con un número aleatorio) Aquí está mi código

 <!DOCTYPE html> <html> <Head> <h2> Random number Generator </h2> </Head> <body> <script src ="Script.js"></script> <button type="button" onclick="alert(randomNum)"> Generate! </button> </body> </html>

y la parte del guión aquí

 function randomNum(result, oneToHundred, randomNum) { let newNumber = Math.random() let oneToHundred = newNumber * 1000 let result = Math.floor(oneToHundred) return result }; alert(randomNum)

Simplemente no puedo entender cómo hacer que el botón busque un script y lo ejecute cuando lo presione. Traté de incrustar la búsqueda de secuencias de comandos en la parte onclick, pero obtuve un error de sintaxis.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Este sería un ejemplo simple.

archivo HTML.

 <!DOCTYPE html> <html> <Head> <h2> Random number Generator </h2> </Head> <body> <script src ="Script.js"></script> <button type="button" onclick="showMessage()"> Generate! </button> </body> </html>

archivo JavaScript.

 function showMessage() { alert("Hello friends, this is random number: " + Math.floor(Math.random() * 11)); }
about 4 years ago · Santiago Trujillo 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!