- js中控制html元素的样式以及普通事件的使用
<script type="text/javascript">
function over(obj) {
obj.style.color = "#f00";
obj.style.fontSize = "20px";
}
function out(obj) {
obj.style.color = "#000";
}
function clic(obj) {
var size = obj.style.fontSize;
if(parseInt(size)) {
obj.style.fontSize = parseInt(size) +2 +"px";
} else {
obj.style.fontSize = "16px";
}
}
</script>
</head>
<body>
<div onmouseover="over(this)" onmouseout="out(this)" onclick="clic(this)">啊啊</div>
</body>
- settimeout() setinterval().clearinterval()函数的使用
<script type="text/javascript">
window.onload= function() {
setTimeout("cd()",3000);
timeId = setInterval("cd()",1000);
}
function stop() {
clearInterval(timeId);
}
function cd() {
var abc = document.getElementById("abc");
abc.style.fontSize = "100px";
}
</script>
</head>
<body>
<div id="abc">啊啊</div>
</body>
- 实现js代码与html页面解耦和
<script type="text/javascript">
window.onload=function() {
var chen = document.getElementById("chen");
chen.onclick=function(event) {
event = event || window.event;
alert(event.type)
alert(chen.textContent);
}
}
</script>
</head>
<body>
<hr>
<h3 id="chen">陈</h3>
<hr>
</body>
js函数 间的赋值
<script type="text/javascript">
function a() {
alert("a");
}
var b = a;
b();
a = function() {
alert("其他");
}
a();
b();