2012-06-28 33 views
0

我試圖改變:在「a」元素更改參數

<a href="www.example.com"> 

本:

<a onclick="parent.location='www.example.com'"> 

而且我要動態地做到這一點,我的意思是,在所有環節我的網站。 我不知道如何做到這一點在functions.php

顯然「www.example.com」不是一個常數。

你們能幫助我嗎?謝謝。

+0

你想硬編碼此爲您的標記或動態地改變它每次的JavaScript? – fuxia

+0

動態更改每個JS – ignaces

回答

2

你可以很容易地使用jQuery來做到這一點。

首先,剝去href屬性,並添加onclick屬性:(抓取您的網站並阻止搜索引擎)

$('a').each(function() { 
    $(this).attr('onclick', 'parent.location=\'' + $(this).attr('href') + '\'').removeAttr('href'); 
});