标签:style blog io 使用 ar java strong sp div
模拟操作:
event = $.Event("keydown"); //keydown event; event.keyCode = 9; $doc.trigger(event);//can use triggerHandler() insteadof trigger;
例子:
function keyLogger(target) { if(!(this instanceof keyLogger)) { return new keyLogger(target); }; this.target = target; this.log = []; var self = this; this.target.off("keydown").on("keydown", function(event) { self.log.push(event.keyCode); }); } QUnit.test("keylogger api behavior", function(assert) { var event, $doc = $(document), keys = keyLogger($doc); //trigger event event = $.Event("keydown"); //keydown event; event.keyCode = 9; $doc.trigger(event);//can use triggerHandler() insteadof trigger; //verify expected behavior assert.equal(keys.log.length,1,"a key was logged"); assert.equal(keys.log[0],9,"correct key was logged"); });
标签:style blog io 使用 ar java strong sp div
原文地址:http://www.cnblogs.com/jinkspeng/p/4026457.html