【发布时间】:2015-12-07 03:42:32
【问题描述】:
我更新了我的代码并重新表述了我的问题:
我正在尝试创建以下条件。当单击具有空 href 属性(例如 href="")的链接时,将启动一个模式并阻止该链接的默认行为..
但是,当 href 属性包含一个值 (href="www.something.com") 时,我希望链接能够正常工作,使用其默认行为。
由于某种原因,我的代码无法正常工作。任何帮助表示赞赏。
// Semicolon (;) to ensure closing of earlier scripting
// Encapsulation
// $ is assigned to jQuery
;(function($) {
// DOM Ready
$(function() {
// Binding a click event
// From jQuery v.1.7.0 use .on() instead of .bind()
$('.launch').bind('click', function(e) {
var attrId = $(this).attr('attrId');
if( $('.launch').attr('href') == '') {
// Prevents the default action to be triggered.
e.preventDefault();
// Triggering bPopup when click event is fired
$('div[attrId="' + attrId+'"]').bPopup({
//position: ['auto', 'auto'], //x, y
appendTo: 'body'
});
} else {
$(this).removeAttribute('attrId');
return true;
}
});
});
})(jQuery);
【问题讨论】:
标签: javascript jquery html