为什么这个 jQuery 代码在行后就无休止地循环
//$('.'+triggerThisChild).trigger("click"); // 这会导致无限循环
未注释FIDDLE 在这里
jQuery代码:
$('a.touchNav').on('click touchend', function (e) {
var fancy = this.className.indexOf('fancy') != -1;
var target = $(this).attr('target') == '_blank' ? true : false;
if (fancy) {
var triggerThisChild = $(this).children('span').attr('class');
alert(triggerThisChild);
e.stopPropagation();
//$('.'+triggerThisChild).trigger("click"); // this causes endless loop
//return false;
} else if (target) {
window.open(this.href,target);
return false;
} else {
window.location = this.href;
return false;
}
});
$(".showFancyBox").fancybox({
"width" : "75%",
"height" : 800,
"transitionIn" : "none",
"transitionOut" : "none",
"type" : "iframe",
'href' : "http://www.google.com"
});
HTML:
<li>
<a class="touchNav" href="http://www.google.com" target="_blank">
Nav Point 1
</a>
</li>
<li>
<a class="touchNav" href="http://www.stackoverflow.com" target="_blank">
Nav Point 2
</a>
</li>
<li>
<a class="fancy touchNav" href="#">
<span class="showFancy0" style="display:none;"></span>
Nav Point 3
</a>
</li>