我有一个内容页面,其中有不同的文件,如.doc,.docx,.ppt .pptx,.txt的链接。
我想动态地应用/添加类,而不是手动。如链接内容所示。
<h3><a href="document.pdf" class="pdf-file">Document.pdf</a></h3>
.pdf-file {
background:url(../images/pdf-file.png) right center no-repeat; padding-right:18px;
}这是我申请的手工类。
jQuery解决方案将被优先考虑。
如果你喜欢我的问题,请点赞。:)谢谢
发布于 2010-01-18 17:57:50
试试这个:
$(document).ready(function() {
$('a[@href$=".pdf"]').addClass('pdflink');
$('a[@href$=".doc"]').addClass('doclink');
$('a[@href$=".docx"]').addClass('docxlink');
$('a[@href$=".ppt"]').addClass('pptlink');
//etc
});发布于 2010-01-18 17:58:02
我知道这不是你想要的,但为什么不这样做:
a[href*=".pdf"].icon {
background:url(../images/pdf-file.png) right center no-repeat; padding-right:18px;
}这样,您在技术上不需要使用JavaScript,CSS足够智能,可以询问href属性并应用适当的CSS属性。
考虑拥有一个look at this article。
https://stackoverflow.com/questions/2085115
复制相似问题