Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- paginaExemploJs.html -->
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Página Exemplo Js</title>
- <script>
- function carregar() {
- alert("Carregou a página");
- }
- function clique() {
- alert("Você clicou");
- }
- function clique2() {
- var variavel = document.getElementById("valor").value;
- alert("Você digitou: "+ variavel);
- }
- function escreve() {
- var today = new Date();
- var dd = today.getDate();
- var mm = today.getMonth()+1;
- var yyyy = today.getFullYear();
- if(dd<10)
- dd = "0" + dd;
- if(mm<10)
- mm = "0" + mm;
- today = dd + "-" + mm + "-" + yyyy;
- document.write("<b>" + today + "</b>");
- }
- function escreve2() {
- var elemento = document.getElementById('elemento');
- elemento.innerHTML = "Oi, tudo bem?"
- var elemento2 = document.getElementById('valor');
- elemento2.value= "teste";
- }
- </script>
- </head>
- <body onload="carregar()">
- Esta é um exemplo de Javascript. <br/>
- <button onclick="clique()">Me clique</button>
- <p>
- Digite algo: <input type="text" name="valor" id="valor">
- <button onclick="clique2()">Clica de novo?</button>
- </p>
- <div>Vai escrever a data ao clicar <a href="#" onclick="escreve()">aqui.</a></div>
- <div>Vai escrever algo clicar <a href="#" onclick="escreve2()">aqui.</a></div>
- <span id="elemento"></span>
- <div>Exercício
- Criar uma página nova chamada calculadora.html
- Na tela devem conter dois inputs do tipo texto com os ids valor1 e valor2. Um terceiro input com id chamado operacao. Um botão que chame a função calcula
- Criar a função em javascript que leia os dois valores e execute a operação digitada (+ - * /).
- Mostar em um alert o resultado e em um elemento span na tela com a id resultado.
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement