JQuery中的事件 (二.事件绑定)

    xiaoxiao2021-03-25  81

    使用bind()方法对匹配元素进行事件绑定

    1.点击正文展开

    $("#panel h5.head").bind("click",function(){ var content = $(this).next(); if(content.is(":visible")){ content.hide(); }else{ content.show(); } })

    2.鼠标滑过正文展开

    $("#panel h5.head").mouseover(function(){ $(this).next().show(); }).mouseout(function(){ $(this).next().hide(); }); <div id="panel"> <h5 class="head">什么是jQuery?</h5> <div class="content"> jQuery是继Prototype之后又一个优秀的JavaScript库,它是一个由 John Resig 创建于2006年1月的开源项目。jQuery凭借简洁的语法和跨平台的兼容性,极大地简化了JavaScript开发人员遍历HTML文档、操作DOM、处理事件、执行动画和开发Ajax。它独特而又优雅的代码风格改变了JavaScript程序员的设计思路和编写程序的方式。 </div> </div> <style> * { margin: 0; padding: 0; } body { font-size: 13px; line-height: 130%; padding: 60px } #panel { width: 300px; border: 1px solid #0050D0 } .head { height: 24px; line-height: 24px; text-indent: 10px; background: #96E555; cursor: pointer; width: 100%; } .content { padding: 10px; text-indent: 24px; border-top: 1px solid #0050D0; display: block; display: none; } </style>

    转载请注明原文地址: https://ju.6miu.com/read-19221.html

    最新回复(0)