找到了一個很好的jQuery彈出功能在這裏:減少重複的代碼與jQuery功能
JAVASCRIPT
$(function() {
$("#word1234").live('click', function(event) {
$(this).addClass("selected").parent().append('
<div class="messagepop pop">"Lorem ipsum dolor sit amet,
consectetur adipisicing elit, sed do eiusmod tempor incididunt</div>');
$(".pop").slideFadeToggle()
$("#email").focus();
return false;
});
$(".close").live('click', function() {
$(".pop").slideFadeToggle();
$("#contact").removeClass("selected");
return false;
});
HTML
<a href='/word1234' id='word1234'>Supercalifragilisticexpialidocious</a>
有沒有調用這個彈出的更有效的方法?如果我在頁面上有數百個定義,我會看起來不必要地重複大量代碼。
如果我在本地JS這樣做,我只是設置的onClick功能的href標記,像
<a href="#" id="word1234" onClick="doPop(this, 'Lorem ipsum, ect.')">Supercalifragilisticexpialidocious</a>
是否有類似的呼籲在JQuery中的函數的方法是什麼?
編輯 一些調試後,更新/固定腳本的工作版本可以在這裏找到:http://jsfiddle.net/N4QCZ/13/心連心。
,而不是一個ID,這限制了您在單個DOM元素,使用一個類,它可以應用於任意多個dom元素。 – 2013-02-12 16:21:59
如何定義彈出內容和元素之間的關係? – 2013-02-12 16:22:02
在我自己的彈出庫中,添加彈出窗口的方法之一是有一個屬性:''. It's easy with jQuery to select elements with the attribute : '$('[bubble]')'. – 2013-02-12 16:23:42