这不起作用,因为它需要我在自动事件注册之前手动单击主体。我需要在页面加载时自动模拟真实的点击事件。以下是我尝试过的内容:
$("document").ready(function() {
$("body,html").click(function() {
console.log("Automatic Click");
});
});
您可以像这样使用click():
$("body,html").click()
$("document").ready(function() {
$("body,html").click(function() { // catch trigger the click
console.log("Automatic Click");
});
$("body,html").click(); // trigger the click
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>