如何在 div 的特定 x 和 y 位置触发点击事件?

How to trigger a click event on specific x and y position of a div?

通过这段代码我得到坐标我不知道如何触发这些 (X = 1043, Y = 73) 坐标 body 加载。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

<div class="rating"></div>

<div id="status"> </div>

<script>

$(document).ready(function(){
$(".rating").click(function(){
  // X = 1043 
  // Y = 73
  var x = event.clientX;
  var y = event.clientY;
  var coords = "X coords: " + x + ", Y coords: " + y;
  document.getElementById("status").innerHTML = coords;
}); 
});

</script>

您可以像这样简单地触发点击事件:

$(".rating").click(function(){
 // your code...
}).click() // triggers on first load/ready

或者,

.trigger('click')
$(function() {
  $('.rating').on('page:click', function(e) {
  var coords = "X coords: " + e.clientX + ", Y coords: " + e.clientY,
  aim = document.elementFromPoint(e.clientX, e.clientY);
  $(aim).click();
  console.log(aim);
  $('#status').text(coords);
  });
  var action = $.Event('page:click', {clientX: 1043, clientY: 70});
  $('.rating').trigger(action);
});