jQuery如何在新窗口中打开链接
更新:HHH   时间:2023-1-7


小编给大家分享一下jQuery如何在新窗口中打开链接,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

在新窗口中打开链接

XHTML 1.0 Strict doesn’t allow this attribute in the code, so use this to keep the code valid. 
 
$(document).ready(function() { 
   //Example 1: Every link will open in a new window 
   $('a[href^="http://"]').attr("target", "_blank"); 
 
   //Example 2: Links with the rel="external" attribute will only open in a new window 
   $('a[@rel$='external']').click(function(){ 
      this.target = "_blank"; 
   }); 
}); 
// how to use 
<a href="http://www.opensourcehunter.com" rel=external>open link</a>

看完了这篇文章,相信你对“jQuery如何在新窗口中打开链接”有了一定的了解,如果想了解更多相关知识,欢迎关注天达云行业资讯频道,感谢各位的阅读!

返回web开发教程...