① 错误处理
第一:try catch错误处理
function f1(){
try{
alert("ss");
add();
} catch (e) {
document.getElementById("err").innerHTML=e.message;
}
}
</script>
<body>
<input type="button" value="错误处理" onclick="f1()" />
<br />
<div id="err"> </div>
第二: 抛出异常
<script type="text/javascript">
function f1(){
var age=document.getElementById("t1").value;
try {
if (age=="") throw "请输入";
else if (isNaN(age)) throw "非数字";
}catch(e) {
document.getElementById("err").innerHTML=e
}
}
<input type="button" value="检查" onclick="f1()" /> <br />
<input type="text" id="t1" />
<br />
<div id="err"> </div>
⑦内置核心对象
String对象,Math对象,Date对象–同java的核心类
window,document,location,history对象 浏览器处理核心类
window 是顶层对象
包括 document,history,location,等
alert(),close(),详见chm文档–http://pan.baidu.com/s/1nvAwLUL
window对象的属性,
status() 状态栏
HISTORY.BACK() 返回上个目录
⑧ 事件处理
<td><input type="text" id="name" onfocus="onfocusFunc()" onblur="onb()" /></td>
<td><div id="name_info"></div></td>
命令按钮事件:onSubmit/onClick
function radioFunc(){
var myfrom=document.forms["myform"];
var _sex=myform.sex;
for (var i=0;i<_sex.length;i++){
if(_sex[i].checked{
alert(_sex[i].value);
break;
}}}
鼠标事件:
onmousemove,onmousedown.onmouseover,ondbclick
⑨正则表达式
[abv|ABC] 或者的关系
[^a]非a
10 DOM操作–文档对象模型
function dom1(){
var p1=document.getElementById("p1");
p1.setAttribute("title","小白");
--p1.style.color="#ff0000";
}
除此之外还有: document.getElementById().innerHTML=”“;
window.onload=function(){
document.getElementById("b3").click=function(){
}
}
DOM节点
增加节点,删除节点
window.onload=function(){
document.getElementById("button").onclick=function(){
var e_p=document.creatElemnet("p");
var text=document.creatTextNode("新创建的段落");
e_p.eppendChild(text):--内容是元素的Child
document.getElementById("div1").appendChild(e_p);--div1.removeChild(e_p) 删除节点
}
}