在这里发现了一个很好的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 中执行此操作,我只需为 href 标记设置一个 onClick 函数,例如
<a href="#" id="word1234" onClick="doPop(this, 'Lorem ipsum, ect.')">Supercalifragilisticexpialidocious</a>
JQuery 中是否有类似的调用函数的方法?
EDIT经过一些调试后,可以在此处找到更新/修复脚本的工作版本:http://jsfiddle.net/N4QCZ/13/ hth.
您可以将代码变成jQuery 插件像这样:
$.fn.myPopup = function(popupText){
var popupHtml = '<div class="messagepop pop">' + popupText + '</div>';
this.each(function(){
$(this).click(function(){
// Create the popup
$(this).addClass("selected").parent().append(popupHtml);
// Find the close button and attach click handler
$(this).find(".close").click(
// Find, hide, then delete the popup
$(this).closest(".pop").slideFadeToggle().remove();;
);
});
return false;
});
return this;
};
那么你的代码将如下所示:
$("#word1234").myPopup("Lorem Ipsum");
$("#wordABCD").myPopup("Hello World");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)