javascript
1.onchange 事件会在域的内容改变时发生
<html>
<head>
<script type="text/javascript">
function upperCase(x)
{
var y=document.getElementById(x).value
document.getElementById(x).value=y.toUpperCase()
}
</script>
</head>
<body>
输入您的姓名:
<input type="text" id="fname" onchange="upperCase(this.id)"
/>
</body>
</html>
2.onclick 事件会在对象被点击时发生
3.ondblclick 事件会在对象被双击时发生
4.onmousedown 事件会在鼠标按键被按下时发生
5.onmouseup 事件会在鼠标按键被松开时发生
6.onmouseover 事件会在鼠标指针移动到指定的对象上时发生
7.onmouseout 事件会在鼠标指针移出指定的对象时发生
8.onblur 事件会在对象失去焦点时发生
<html>
<head>
<script type="text/javascript">
function upperCase()
{
var x=document.getElementById("fname").value
document.getElementById("fname").value=x.toUpperCase()
}
</script>
</head>
<body>
输入您的姓名:
<input type="text" id="fname" onblur="upperCase()"
/>
</body>
</html>
9.onfocus 事件在对象获得焦点时发生
jQuery
1.当元素的值发生改变时,会发生 change 事件
当输入域发生变化时改变其颜色:
$(".field").change(function(){ $(this).css("background-color","#FFFFCC"); });
2.当点击元素时,会发生 click 事件
3.当双击元素时,会发生 dblclick 事件
4.当鼠标指针移动到元素上方,并按下鼠标按键时,会发生 mousedown 事件
5.当在元素上放松鼠标按钮时,会发生 mouseup 事件
6.当鼠标指针位于元素上方时,会发生 mouseover 事件
7.当鼠标指针从元素上移开时,发生 mouseout 事件
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").mouseover(function(){
$("p").css("background-color","yellow");
});
$("p").mouseout(function(){
$("p").css("background-color","#E9E9E4");
});
});
</script>
</head>
<body>
<p style="background-color:#E9E9E4">请把鼠标指针移动到这个段落上。</p>
</body>
</html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("p").mouseover(function(){
$("p").css("background-color","yellow");
});
$("p").mouseout(function(){
$("p").css("background-color","#E9E9E4");
});
});
</script>
</head>
<body>
<p style="background-color:#E9E9E4">请把鼠标指针移动到这个段落上。</p>
</body>
</html>
8.当元素失去焦点时发生 blur 事件
9.当元素获得焦点时,发生 focus 事件