javascript-如何使用jquery将target = _blank添加到div中的所有PDF链接? [英] How to add target=_blank to all PDF links inside div using jquery?
本文介绍了javascript-如何使用jquery将target = _blank添加到div中的所有PDF链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
我想在此css类"class="newWindow"
添加脚本之前
<div class="newWindow" >
<a href="pdf1.pdf">link text</a>
<a href="pdf2.pdf">link text</a>
</div>
添加脚本后
<div class="newWindow" >
<a href="Pdf1.pdf" target="_blank">link text</a>
<a href="Pdf2.pdf" target="_blank">link text</a>
</div>
请提供没有冲突的jquery代码.
推荐答案
代码
$(".newWindow a[href$='pdf']").attr('target','_blank');
:]
在jsbin示例中,我还添加了类.bl
,因此您可以轻松查看结果:]
in jsbin example, I also add class .bl
, so you can easily see result :]
jQuery.noConflict();
jQuery(".newWindow a[href$='pdf']").attr('target','_blank');
或
jQuery.noConflict();
jQuery(document).ready(function($){
$(".newWindow a[href$='pdf']").attr('target','_blank');
});
或其他方式,请在此处查看: http://docs.jquery.com/Using_jQuery_with_Other_Libraries
or another way, take a look here: http://docs.jquery.com/Using_jQuery_with_Other_Libraries
这篇关于javascript-如何使用jquery将target = _blank添加到div中的所有PDF链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文