【问题标题】:Add target="_blank" for links not working after ajax call为 ajax 调用后不工作的链接添加 target="_blank"
【发布时间】:2020-06-19 18:06:47
【问题描述】:

我正在使用这个 jQuery sn-p 使该部分中的所有链接在新选项卡中打开。在我进行 ajax 调用之前它工作正常。那么这个脚本就没有效果了。

知道如何针对 ajax 优化它吗?

jQuery(document).ready(function( $ ) {

  $("#my-section a").attr("target","_blank");
  
});

感谢您的帮助!

干杯, 托斯滕

【问题讨论】:

    标签: jquery ajax attr


    【解决方案1】:

    我一直在使用“.on”,这似乎有效:

    jQuery("#my-section").on('click', 'a', function(event) {
        jQuery("#my-section a").attr("target","_blank");
    
    });
    

    :-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多