0

我已经尝试了一段时间,但我找不到解决方案,希望您能提供帮助。

我有一个指向这样的 youtube 视频的链接

    <a id='LinkClick1' href='www.youtube.com' target='_blank'><strong>Title</strong></a>

并且我希望在单击该链接时进行注册,但是每次单击它都会在另一个选项卡中打开该网站,并且不会执行我的功能

    $("#LinkClick1").click( function(){
      var a='Hi!';
      var clicked='yes';
      console.log(a+clicked);
    });

我怎样才能让我的链接点击打开网站但也触发一个功能?

谢谢你。

4

1 回答 1

1

另一个DEMO ...在弹出框内带有链接,如问题中的评论中所述。

http://jsfiddle.net/weuWk/1126/

相关代码..

var img = '<a href="https://si0.twimg.com/a/1339639284/images/three_circles/twitter-bird-white-on-blue.png" target="_blank" id="1">TEST</a>';
$("#blob").popover({
  trigger: "manual",
content: img    
}).on("click", function(e) {
  e.preventDefault();
}).on("mouseenter", function() {
  $(this).popover("show");
  $(this).siblings(".popover").on("mouseleave", function() {
    $(this).hide();
  });
}).on("mouseleave", function() {
  var _this = this;
  setTimeout(function() {
    if (!$(".popover:hover").length) {
      $(_this).popover("hide")
    }
  }, 100);
});

$(document).on('click', '#1',function(){
console.log("CLicked");
});

考虑到 bootrstrap 弹出框进行更新。如果它仍然不适合您,请更好地显示 HTML,甚至更好地在 jsfiddle 上显示您的问题 DEMO。

http://jsfiddle.net/AFffL/547/

<a class="popup-marker btn" data-content="Click outside the popover to close it." data-original-title="Popover A" href="youtube.com" target="_blank">Click me (A)</a>

jQuery(function() {


    $('.popup-marker').popover().on('click', function(e) {
        // if any other popovers are visible, hide them
        var a='Hi!';
       var clicked='yes';
      console.log(a+clicked);
    });


});

_---------------------------------------------------- ---

您显示的代码确实按照您所说的做......参见演示

http://jsfiddle.net/tymeJV/CE2k5/ (.. 由 tymeJV 在评论中)...

但是,如果链接在运行时由dom manipulation或加载Ajax,那么您的代码可能无法正常工作。在这种情况下,请尝试以下代码。

$(document).on('click','#LinkClick1',function(){
      var a='Hi!';
      var clicked='yes';
      console.log(a+clicked);
    });

而不是$(document)你可以Selector for parent使用#LinkClick1

于 2013-05-30T15:24:59.563 回答