gpt4 book ai didi

javascript - 如何用鼠标单击页面上的按钮,然后触发同一页面上链接的单击?

转载 作者:行者123 更新时间:2023-12-02 23:13:09 24 4
gpt4 key购买 nike

我有一个学习管理 Wordpress 主题,可以根据您所在的视频自动生成指向上一个和下一个视频的链接(视频 2 在视频说明中将具有指向视频 1 的上一个链接和指向视频 3 的下一个链接)。

我想在自定义视频播放中添加上一个和下一个按钮,单击这些按钮会触发 WordPress 主题已生成的上一个和下一个链接。

如何创建一个按钮,单击该按钮后会单击同一页面上的链接?

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>HTML 5 VIDEO PLAYER</title>
<script src="main.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<link href="font-awesome/css/all.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>
<body>
<!-- Previous & Next Video Buttons -->
<div id="video-arrows">
<button type="button" id="previous-arrow"><a href="previous-video"></a><i class="fas fa-chevron-left"></i></button>
<button type="button" id="next-arrow"><a href="next-video"></a><i class="fas fa-chevron-right"></i></button>
</div>
<div class="random-text">
<h1>Video title</h1>
<h4><span id="view-count"></span> views</h4>
<p>Descriptions can convey valuable information that helps viewers find your videos in search results and understand what they’ll be watching. Well-written descriptions with the right keywords can boost views and watch time because they help your video show up in search results.</p>
<a href="https://www.icloud.com/" target="_blank" id="previous-video">Previous</a>
<a href="https://google.com" target="_blank" id="next-video">Next</a>
</div>
</body>
</html>

window.onload = function() {
var nextArrow = document.getElementById('next-arrow')
var prevArrow = document.getElementById('previous-arrow')
$(document).ready(function(){
$(nextArrow).on('click', function () {
$('#next-video').click();
});
$(prevArrow).on('click', function () {
$('#previous-video').click();
});
});
}

它不会给出任何错误,只是不起作用

最佳答案

尝试 $('#next-video')[0].click();

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<button onclick="console.log('A')" id="A">A</button>
<button onclick="$('#A')[0].click()">B</button>

关于javascript - 如何用鼠标单击页面上的按钮,然后触发同一页面上链接的单击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57263358/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com