0
我有一個ASP搜索腳本,它返回的結果主要是PDF和一些其他文檔。在該站點的大部分中,我使用名爲clueTip的jQuery插件(由Karl Swedberg創建),當用戶將鼠標懸停在某些鏈接上時創建工具提示。這些鏈接的內容是通過AJAX從鏈接的rel屬性定義的HTML文件拉:如何添加基於href文件名的rel屬性
<a href="../../example.pdf" class="tips" rel="../../tooltips/example.html>
當用戶執行搜索我希望能夠動態地這些提示從一個特定添加到PDF文件位置 - ../../technicalarticles
。所以,我需要:
- 找到任何返回在
../../technicalarticles
,並添加class="tips"
到鏈接 - 從那些我需要(從最後
/
一切文件擴展名)提取相關文件的名稱PDF文件的PDF文件 - 追加該文件名的
rel
屬性
下面是我的jQuery代碼至今:
<script type="text/javascript">
$(".results a").each(function() {
if (window.location.href.indexOf("technicalarticles") >= 0)
// if statement to find the right pdfs
{
var firstpos = location.href.lastIndexOf('/')+1; // finds the position of the last/and adds 1
var lastpos = location.href.lastIndexOf('.')-1; // finds the position of the last . and subtracts 1
var filename = location.href.substr(firstpos, lastpos); // filename should now have eveything from the last/to the file extension
$(this).attr('rel', ".data/tooltips/" + filename + ".html"); // adds the rel string to the link
$(this).addClass('tips'); // adds the class 'tips' to the link
}
});
</script>