youthdream

 项目里用到了一个用js生成的链接

$("<a href=\'www.google.com.hk\'>google</a>").appendTo(".example");

后来这个链接又要实现从新窗口打开,于是修改了一下代码。

方法一:

$("<a href=\'www.google.com.hk\' target=\'_blank\'>google</a>").appendTo(".example");

方法二:

给这个链接一个类名,再给这个类名一个点击自动加target属性的动作

$("<a href=\'www.google.com.hk\' class=\'open_in_tab\'>google</a>").appendTo(".example");

$(\'.zyzx_open_in_new_tab\').click(function() {
if (!$(this).attr("target")) {
$(this).attr(\'target\',\'_blank\');
}
});

分类:

技术点:

相关文章:

  • 2021-12-19
  • 2021-12-19
  • 2022-12-23
  • 2021-11-17
  • 2022-01-06
  • 2022-02-18
  • 2021-10-11
猜你喜欢
  • 2021-06-07
  • 2021-12-27
  • 2021-10-24
  • 2021-12-08
  • 2022-12-23
  • 2021-08-29
相关资源
相似解决方案