function fakeClick(fn) { var $a = $(‘<a href="#" id="fakeClick"></a>‘); $a.bind("click", function(e) { e.preventDefault(); fn(); }); $("body").append($a); var evt,el = $("#fakeClick").get(0); if (document.createEvent) { evt = document.createEvent("MouseEvents"); if (evt.initMouseEvent) { evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); el.dispatchEvent(evt); } } $(el).remove(); } var _this = this; $(function() { fakeClick(function() { //TODO }); });
时间: 2024-11-06 23:22:59