如果我在可點擊區域放置rel =「external」的新插件中使用jquery裝*插件,但是點擊鏈接打開2次, 如何解決這個問題?在jquery插件中使用rel external打開鏈接2次
例如: 我有:
<p>
text <a rel="external" href="/link">text2</a>
</p>
文本打開完美的一次,但單擊文本2的鏈接打開兩次
代碼:
if(typeof jQuery != 'undefined') {
jQuery(function($) {
$.fn.extend({
fitted: function(options) {
var settings = $.extend({}, $.fn.fitted.defaults, options);
return this.each(
function() {
var $t = $(this);
var o = $.metadata ? $.extend({}, settings, $t.metadata()) : settings;
if($t.find(':has(a)')) {
/**
* Find the first Anchor
* @var object $a
*/
var $a = $t.find('a:first');
/**
* Get the Anchor Attributes
*/
var href = $a.attr('href');
var title = $a.attr('title');
/**
* Setup the Container
* Add the 'container' class defined in settings
* @event hover
* @event click
*/
$t.addClass(o['class']['container']).hover(
function(){
/**
* Hovered Element
*/
$h = $(this);
/**
* Add the 'hover' class defined in settings
*/
$h.addClass(o['class']['hover']);
/**
* Add the Title Attribute if the option is set, and it's not empty
*/
if(typeof o['title'] != 'undefined' && o['title']===true && title != '') {
$h.attr('title',title);
}
/**
* Set the Status bar string if the option is set
*/
if(typeof o['status'] != 'undefined' && o['status']===true) {
if($.browser.safari) {
/**
* Safari Formatted Status bar string
*/
window.status = 'Go to "' + href + '"';
}
else {
/**
* Default Formatted Status bar string
*/
window.status = href;
}
}
},
function(){
/**
* "un"-hovered Element
*/
$h = $(this);
/**
* Remove the Title Attribute if it was set by the Plugin
*/
if(typeof o['title'] != 'undefined' && o['title']===true && title != '') {
$h.removeAttr('title');
}
/**
* Remove the 'hover' class defined in settings
*/
$h.removeClass(o['class']['hover']);
/**
* Remove the Status bar string
*/
window.status = '';
}
).click(
function(){
/**
* Clicked!
* The Container has been Clicked
* Trigger the Anchor/Follow the Link
*/
if($a.is('[rel*=external]')){
window.open(href);
return true;
}
else {
//$a.click(); $a.trigger('click');
window.location = href;
}
}
);
}
}
);
}
});
/**
* Plugin Defaults
*/
$.fn.fitted.defaults = {
'class' : {
'container' : 'fitted',
'hover' : 'hovered'
},
'title' : true,
'status' : true
};
});
}
*: http://www.trovster.com/lab/plugins/fitted/
如何解決這個問題?可以修復?
非常感謝你