var on = 0;
var typingData = "some Text i want to simulate";
function simulateKeyPress(character) {
jQuery(this).trigger({
type : 'keypress',
which : character
});
}
function justtype() {
if (typingData.length) {
console.log("justtype");
simulateKeyPress(typingData);
}
}
var bd = document.getElementsByTagName('body')[0];
bd.onmousedown = function() {
if (on == 0) {
console.log("mousedown");
myInt = setInterval(justtype, 1);
on = 1;
}
};
bd.onmouseup = function() {
if (on == 1) {
console.log("mounseup");
window.clearInterval(myInt);
on = 0;
}
};
我已创建此代码用于模拟存储在typingData
变量中的字符串。
当我在主体上单击鼠标但未模拟变量中的文本时,将调用所有三个函数。问题在哪里?