向网页上的所有链接添加javascript操作

向网页上的所有链接添加javascript操作,javascript,joomla,Javascript,Joomla,早上好,我想知道是否可以自动向网页上的所有链接(或类)添加javascript操作,例如,我想添加以下javascript操作:“PlayFlashSound();”,因此我网页上的链接应该是: <a onmouseover="PlayFlashSound();" href="#">Link Text</a>" ” 手动添加javascript操作的问题在于我使用的是Joomla,而我不知道如何操作 谢谢。使用jQuery,您可以这样做 $(document).rea

早上好,我想知道是否可以自动向网页上的所有链接(或类)添加javascript操作,例如,我想添加以下javascript操作:“PlayFlashSound();”,因此我网页上的链接应该是:

<a onmouseover="PlayFlashSound();" href="#">Link Text</a>"
手动添加javascript操作的问题在于我使用的是Joomla,而我不知道如何操作


谢谢。

使用jQuery,您可以这样做

$(document).ready(function() {

    $('a').click(function() {

        PlayFlashSound();

        return false

    });

});

使用jQuery可以很容易地实现这样的功能:

$('a').mouseover(function()
{
    PlayFlashSound();
});

我假设,由于这个问题标签中的一个是“joomla”,因此作者希望使用joomla CMS中包含的Mootool完成所需的工作。例如,代码可能如下:

window.addEvent(“domready”, 函数(){

})

请记住,如果您希望阻止这些链接的默认操作,PlayFlashSound函数必须返回“false”

$$('a').each(function(item, index) {

    item.addEvent('click', PlayFlashSound);
});