1、try ..cathc...finally语句
try 检测异常关键字,
catch 捕捉异常关键字,
finally最后的返回语句。
2、JS中的try ..cathc...finally只能有一个catch语句,但可以在catch语句中嵌套多个try ..cathc...语句。
catch{
tyr{
}
catch{}
}
<script language = "javascript">
try{
somestatemnts; //一些会报错的语句
}
catch(exception){
alert("Try区域报错了")
try{
somestatemnts; //一些会报错的语句
}
catch(exception){
alert("Try区域报错了");
}
finally{
somestatemnts;
}
3、catch捕捉的对象是Error对象。JS中异常的基类是Error,Java中是Exception。
Error对象有2个属性:message和name
exception.message //返回异常的具体报错
exception.name //返回异常类型
在try语句中使用throw语句可以实现在catch语句中抛出具体设定好的异常,即抛出自定义的异常。
try{
var num = 1/0;
if (num = = Infinity){
throw new Error("被除数不能为0") } //定义了一个Error对象
catch(exception){
alert(exception.message); //输出为被除数不能为0
}
4、使用wrtite()方法进行调试 ,优点是比较清晰、直接
function name1(){
document.write("程序开始");
var a = 1; var b=2;
document.write("程序执行");
document.write("a+b"); //输出a+b的值
document.write("程序结束");
}
5、JS是基于对象的语言,它的一个基本的特征就是采用事件驱动。
事件驱动在JS里是指由鼠标或热键引发的一连串程序动作。
、
6、form表单的提交方式可以通过按钮的方式来:
<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
<form action="login.do?act=login" method="post">
用户帐号<input type=text name="userId" size="18" value="" ><br>
登录密码<input type="password" name="password" size="19" value=""/>
<input type=submit name="submit1" value="登陆" οnclick="return check(this.form)">
</form>
7、事件响应:
<form id="form1" name="form1" action="" method="post">
<input id="save" name="save" type="button" value="保存" />
</form>
<script language="javascript">
form1.save.onclick = function(){ //不能在onclick 后面再加()
alert("单击了保存按钮");
}
</script>
8、DOM文档对象模型,它是一个树形结构,有根节点有子节点。
9、页面事件,是指页面加载时,或者改变浏览器的大小、位置时,以及对页面中的滚动条进行操作时,所触发的事件处理程序。
加载事件:onload
卸载事件:unload //指关闭当前页或者从当前页跳转到其它页面。
10、表单的相关事件:
onfocus获得焦点事件
onblur失去焦点事件
11、form表单的功能主要用于收集信息。
真正处理表单的数据脚本或者程序是放在action属性里,这个值可以是程序,或者脚本的一个URL。
method = “post” 决定表单中已经收集到的数据是用什么方式提交到服务器的。