<html> <script type="text/javascript">
function fun(){ with(document){<!--下面出现的document对象中的方法可以不用document.--> with(Math){<!--下面出现的Math对象中的方法可以不用Math.--> <!--document.write("绝对值 abs() :",abs(2-20),"<br/>");这个是输出到浏览器。会清空之前的。--> <!--用DIV的ID去控制,写到DIV里去--> var div=document.getElementById("div_id"); div.innerHTML=div.innerHTML+"绝对值 abs() :"+abs(2-20)+"<br/>"; } } }
function fun2(){ alert("这是另外一个函数"); } </script> <div id="div_id"> Math类中的各种方法<br/> </div> </head> <body> <!--同时调用两个函数且fun()函数在当前页面中显示所输写内容,而不覆盖原页面内容-->
<input type="button" onclick="fun(),fun2()" value="单击我!"> </body> </html> |
|
来自: 风雨电雷 > 《javascript》