我正在上一个网站设计课程,我的第一个项目是在页面加载时刺激鼠标单击音频播放器。
我的网站分为3个文件:HTML,CSS和JS。
当前代码为:
function onPlayerReady(event) {
var playButton = document.getElementById("play");
playButton.addEventListener("click", function() {
player.playAudio();
});
var pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", function() {
player.pauseAudio();
});
}
<div class="buttons">
<svg class="button" id="play">
<use xlink:href="#play">
</svg>
<svg class="button" id="pause">
<use xlink:href="#pause">
</svg>
</div>
答案 0 :(得分:0)
DOM元素具有单击功能,可让您执行此操作。
line 383, in run_background_function
_function_handler.invoke_user_function(event_object)
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function return call_user_function(request_or_event)
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 214, in call_user_function event_context.Context(**request_or_event.context))
File "/user_code/main.py", line 9, in hello_pubsub pubsub_message = base64.b64decode(event['protoPayload']).decode('utf-8') KeyError: 'protoPayload'
答案 1 :(得分:0)
借助 .click()的帮助,您可以手动触发按钮单击方法。 因此,在您的情况下,如果您要自动点击播放按钮,则必须编写
// this function will execute automatically when page all contents are ready/loaded
$(document).ready(function(){
//add click event lister
onPlayerReady(event);
//auto click button with help of
playButton.click();
});
Fore More detail you can find jquery document