jQuery之事件绑定
生活随笔
收集整理的這篇文章主要介紹了
jQuery之事件绑定
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
bind() 方法為被選元素添加一個(gè)或多個(gè)事件處理程序,并規(guī)定事件發(fā)生時(shí)運(yùn)行的函數(shù)。
下面是具體的用法:
<script type="text/javascript"> $(function(){$head = $("#panel h5.head");//選中$head.bind("click",function(){//如果點(diǎn)擊,就會(huì)觸發(fā)事件,將下面的內(nèi)容顯示出來(lái)$(this).next().show();}) }) </script>is(":hidden")可以判斷對(duì)象是否隱藏。
is(":visible")可以判斷對(duì)象是否可見(jiàn)。
<script type="text/javascript"> $(function(){$("#panel h5.head").bind("click",function(){var $content = $(this).next();if($content.is(":visible")){//如果可見(jiàn),將其隱藏。如果隱藏,將其可見(jiàn)。 $content.hide();}else{$content.show();}}) }) </script>mouseover鼠標(biāo)飄過(guò)。
<script type="text/javascript"> $(function(){$("#panel h5.head").bind("mouseover",function(){$(this).next().show();//飄過(guò)顯示 });$("#panel h5.head").bind("mouseout",function(){$(this).next().hide();//飄離隱藏 }) }) </script>直接將事件簡(jiǎn)寫(xiě)成如下的方式也可以:
<script type="text/javascript"> $(function(){$("#panel h5.head").mouseover(function(){$(this).next().show();});$("#panel h5.head").mouseout(function(){$(this).next().hide();}) }) </script>總結(jié)
以上是生活随笔為你收集整理的jQuery之事件绑定的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 玩转Win10的45个快捷键
- 下一篇: 虚拟机安装(Cent OS)