AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

HTML JavaScript


Next Page >>
HTML images

Tutorial HTML » HTML JavaScript

JavaScript hace que las páginas HTML sean más dinámicas e interactivas.

Un script es un pequeño programa que puede agregar interactividad a su sitio web.
Por ejemplo, una secuencia de comandos podría generar un mensaje de cuadro de alerta emergente o proporcionar un menú desplegable.
Este script se puede escribir usando JavaScript o VBScript.

Puede mantener el código JavaScript en un archivo separado y luego incluirlo donde sea necesario, o puede definir la funcionalidad dentro del propio documento HTML. Veamos ambos casos uno por uno con ejemplos adecuados.

 

JavaScript externoL

Si va a definir una funcionalidad que se utilizará en varios documentos HTML, entonces es mejor mantener esa funcionalidad en un archivo JavaScript separado y luego incluir ese archivo en sus documentos HTML. Un archivo JavaScript tendrá la extensión .js y se incluirá en los archivos HTML mediante la etiqueta <script>.

Ejemplo
Considere que definimos una pequeña función usando JavaScript en script.js que tiene el siguiente código:

script.js
función Hola() {
alert ("Hola, mundo");
}

Ahora hagamos uso del archivo JavaScript externo anterior en nuestro siguiente documento HTML:

Ejemplo
<!DOCTYPE html>
<html>

<head>
<title> Secuencia de comandos externa de JavaScript </title>
<script src = "script.js" type = "text / javascript" /> </script>
</head>

<cuerpo>
<input type = "button" onclick = "Hola();" name = "ok" value = "Haz clic aqui" />
</body>
</html>

 

Guión interno - ejemplos

Puede escribir su código de secuencia de comandos directamente en su documento HTML. Por lo general, mantenemos el código de secuencia de comandos en el encabezado del documento usando la etiqueta <script>; de lo contrario, no hay restricción y puede colocar su código fuente en cualquier lugar del documento, pero dentro de la etiqueta <script>.

Ejemplo
<!DOCTYPE html>
<html>

<head>
<title>Script interno de JavaScript</title>
<base href = "https://www.agernic.com/" />

<script type = "text/JavaScript">
function Hello() {
alert("Hola, Mundo");
}
</script>
</head>

<body>
<input type = "button" onclick = "Hello();" name = "ok" value = "Haz click aqui" />
</body>

</html>
Nota: Puede aprender mucho más sobre JavaScript HTMLen nuestro Tutorial.

 

JavaScript puede cambiar estilos:

Puede establecer el color de los bordes: (Puede establecer el color de los bordes :)

Ejemplo:
<!DOCTYPE html>
<html>
<body>

<h1> Mi primer JavaScript </h1>

<p id = "demo"> JavaScript puede cambiar el estilo de un elemento HTML. </p>

<script>
function myFunction () {
document.getElementById ("demostración"). style.fontSize = "25px";
document.getElementById ("demo"). style.color = "rojo";
document.getElementById ("demo"). style.backgroundColor = "amarillo";
}
</script>

<button type = "button" onclick = "myFunction ()"> ¡Haz clic en mí! </button>

</body>
</html>

 



Etiquetas: función javascript html, ejemplo html javascript, cómo usar javascript en html, cómo incluir javascript externo en html, html script src, tutorial de javascript, vincular javascript a html,
Cómo usar javascript en html - html.es

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


1
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.