标签:空值 orm images class oct ide round rac use
函数
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>MyGod</title> <script> function disp() //函数,一般写在head中 { alert("Hello World!"); //消息提示 } </script> </head> <body> <script type="text/javascript"> document.write("<h1> Hello World!</h1>"); //在页面上输出内容 </script> <input type="button" value="OK" onclick="disp()"> //点击按钮 </body> </html>
变量定义
//JavaScript变量是弱类型,对大小写敏感
//可用数据类型有: 整型、浮点型、布尔型、转义字符、字符串、空值(null)等
var x=5;
var flag=true;
var carname="Benz"
函数示例1
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>MyGod</title> <script> function show() { alert(document.getElementById("username").value); //得到id对应的对象,输出其值 } </script> </head> <body> <form> <input type="text" id="username"> <input type="button" onclick="show()" value="提交"> </form> </body> </html>
函数示例2
<html> <head> <script> function add(a,b) //参数不指定类型 { return a+b; } //有返回值也不能指定类型 </script> </head> <body> 6+5=<script>document.write(add(6,5))</script> </body> </html>
confirm函数
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>MyGod</title> <script> function exit_confirm() { var r=confirm("确认退出?"); if(r==true) { window.close(); } else return; } </script> </head> <body> <input type="button" onclick="exit_confirm()" value="退出"> </body> </html>
标签:空值 orm images class oct ide round rac use
原文地址:http://www.cnblogs.com/wust-ouyangli/p/6035519.html