提示:您只能在 HTML 输出中使用 document.write。如果您在文档加载后使用该方法,会覆盖整个文档。
结果:
alert(“我是警告框”),当使用这个函数的时候页面会弹出一个框框; /*三种弹出框的测试*/ <script> function testAlert(){ alert("警告框!"); } function testPrompt(){ prompt("请输入密码","123456"); } function testConfirm(){ confirm("确认框");/*会返回一个boolean型的返回值,点击确定返回true反之false*/ } function test(){ document.write("<p>哈哈</p>"); } </script> <button onclick="testAlert()">警告框</button> <button onclick="testPrompt()">对话框</button> <button onclick="testConfirm()">确认框</button> <button ondblclick="test()">双击</button>结果:
alert:
Prompt:
Confirm:
双击buttonhou:
结果:
/*改变span标签的文本内容*/ function testSpan(){ var html=document.getElementById("span"); html.innerHTML="哦多克"; html.style.color="red"; html.style.fontSize="50px"; } /*改变img中的图片*/ <script> function testimage(){ var image=document.getElementById("image"); /*if(count%2==1){ image.src="true.jpg"; }else if(count%2==0){ image.src="false.jpg"; } count++; alert(image.src);*/ if(image.src.match("false")){ image.src="true.jpg"; }else{ image.src="false.jpg"; } } <script> <body> <img src="false.jpg" id="image" onclick="testimage()"/> </body> <!--这个样子就可以有个点击开关灯的效果-->