根据目标文件类型有选择地启动链接到href事件的函数?

时间:2016-04-21 14:43:17

标签: javascript

我有大量的href,比如这个:

<a class="download " target="_self" href="../res/DOC140416-1.pdf" download="DOC140416-1.pdf

其他人不会以pdf文件为目标。

有没有办法只为目标pdf文件的href调用js函数?

我正在寻找一个从index.html加载的js函数,这个函数在整个&#34; site&#34; (它适用于混合应用程序)。

谢谢。

1 个答案:

答案 0 :(得分:0)

使用jQuery,您可以选择指向PDF文件的所有链接,并在点击这些链接时执行JS功能。

$('A[href$=\\.pdf]').click(function() {
    alert('here'); //Do whatever you want
    return false; //Returning false to skip link normal behavior
});