模拟鼠标单击
我的猜测是网页正在监听mousedown而不是点击(这对于可访问性是不利的,因为当用户使用键盘时,只会触发焦点和点击,而不是mousedown)。所以你应该模拟mousedown,click和mouseup(顺便说一句,它是iPhone,iPod Touch和iPad在点击事件上做的事情)。
要模拟鼠标事件,可以将此代码段用于支持DOM 2 Events的浏览器。要获得更加简单的模拟,请使用填充鼠标位置initMouseEvent。
// DOM 2 Events
var dispatchMouseEvent = function(target, var_args) {
var e = document.createEvent("MouseEvents");
// If you need clientX, clientY, etc., you can call
// initMouseEvent instead of initEvent
e.initEvent.apply(e, Array.prototype.slice.call(arguments, 1));
target.dispatchEvent(e);
};
dispatchMouseEvent(element, 'mouseover', true, true);
dispatchMouseEvent(element, 'mousedown', true, true);
dispatchMouseEvent(element, 'click', true, true);
dispatchMouseEvent(element, 'mouseup', true,