Javascript html添加onclick到标签元素

时间:2017-12-12 14:42:00

标签: javascript jquery onclick

我想将其添加到链接中。

onclick="javascript:window.location='mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location;"

所以它给出了

<a id="email" href="#" onclick="javascript:window.location='mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location;">Email</a>

我尝试过类似的事情:

 $("#email").find("a").onclick = function () {
        javascript:window.location= 'mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location;
    }

但它不起作用。

1 个答案:

答案 0 :(得分:1)

onclick事件已弃用。试试这个:

$("a#email").click(function () {
    window.location.href = 'mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location.href;
}