js面向過程與物件導向編程樣本(使用jquery庫)__小程式

來源:互聯網
上載者:User
<!DOCTYPE html><html><head><style type="text/CSS">.firstDiv{ float:left; background:pink;}.firstDiv:hover{ cursor:pointer;}.noSelected{ -moz-user-select:none; -webkit-user-select:none; -ms-user-select:none; user-select:none;}.secondDiv{ background:gray; width:200px; height:400px; float:left; display:none; padding-top:30px; padding-left:30px;}</style></head><body><div id="firstDiv" class="firstDiv"><span class="noSelected">滑鼠滑動查看資訊。</span></div><div id="secondDiv" class="secondDiv"><p>qq:1900098</p><p>tel:99998888</p><p>user:xq</p></div><script type="text/JavaScript" src="../publicJQuery/jquery-2.1.4.js"></script><script type="text/JavaScript">/*面向過程編程,首先得到某某,然後執行某某操作,敘事般往下走$("#firstDiv").hover(function(){$("#secondDiv").css("display","block");} , function(){$("#secondDiv").css("display","none");});$("#secondDiv").hover(function(){$("#secondDiv").css("display","block");} , function(){$("#secondDiv").css("display","none");});*//*建立一個showAndHideDiv對象,屬性為傳入的參數,方法為show()跟hide()方法*/function showAndHideDiv(element){/* 不明顯的物件導向this.show=function(){$(element).css("display","block");}this.hide=function(){$(element).css("display","none");}*/this.element=element;}showAndHideDiv.prototype={show:function(){$(this.element).css("display","block");},hide:function(){$(this.element).css("display","none");}}var divForChange=new showAndHideDiv("#secondDiv");$("#firstDiv,#secondDiv").hover(function(){divForChange.show();} ,function(){divForChange.hide();});//$("#secondDiv").hover( function(){divForChange.show();}, function(){divForChange.hide();});</script></body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.