常用javascript与jQuery事件

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>

8.当元素失去焦点时发生 blur 事件

9.当元素获得焦点时,发生 focus 事件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值