I use Youtube subscribe button (https://developers.google.com/youtube/youtube_subscribe_button ).
Is there any way, while user clicks on it, to initiate my javascript function too?
I use Youtube subscribe button (https://developers.google.com/youtube/youtube_subscribe_button ).
Is there any way, while user clicks on it, to initiate my javascript function too?
您只需要添加一个具有您需要运行的功能的数据元素。
<script>
function myEvent(e)
{
// do something here
}
</script>
<div class="g-ytsubscribe" data-channel="GoogleDevelopers" data-onytevent="myEvent"></div>
https://developers.google.com/youtube/youtube_subscribe_button#Handling_Events_Demo
只需将函数的名称放在 onclick 中,如下所示:
<div id="whatever they make you call it" onclick="yourFunction();" />
或在 javascript 中执行此操作
document.getElementById("whatever it's called").onclick = "yourFunction();";
我并不是说这是一个好主意,它可能会违反他们的使用条款,但这是我会尝试的。