JavaWeb前端知识-JavaScript进阶

① 错误处理
第一: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) 删除节点
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值