<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body> <h1>我的第一段 JavaScript</h1> <p>JavaScript 能够对事件作出反应。比如对按钮的点击:</p> <p id="demo">JavaScript change HTMLelement Content</p> <script type="text/javascript"> function box() { alert(‘aaa‘); } function myFunction() { x = document.getElementById("demo"); // 找到元素 x.innerHTML = "Hello JavaScript改变内容!"; // 改变内容 alert(‘aaa‘); } function myadd() { var x =parseInt( document.getElementById(‘a‘).value) var y = Number(document.getElementById(‘b‘).value) document.getElementById(‘c‘).value=x+y; } function mysub(a, b) { a + b; } function changeImage() { element = document.getElementById(‘myimage‘) if (element.src.match("pic1")) { element.src = "file:///C:/Users/Administrator/Pictures/img/b.bmp"; } else { element.src = "file:///C:/Users/Administrator/Pictures/img/pic1.png" } } </script> <input id="a"> <div style="HEIGHT: 19px; WIDTH: 22px; POSITION: relative; DISPLAY: inline" ms_positioning="FlowLayout">+</div> <input id="b"> <input type="button" value="=合计" onclick="myadd()"> <input id="c"> <img id="myimage" onclick="changeImage()" src="file:///C:/Users/Administrator/Pictures/img/pic1.png"> </body> </html>
时间: 2024-10-03 21:02:51