$.Event不是函数错误

$.Event is not a function error

本文关键字:函数 错误 Event      更新时间:2023-09-26

我正在创建一个简单的Javascript BOT。它是一个简单js bookmarklet,点击后将在Blogger.com中创建博客…我使用了以下代码

var script = document.createElement('script');
script.src = 'http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
document.getElementsByClassName('blogg-button GEE3RVNDMU')[0].click()
document.getElementById("newBlog-title").value ="hello blogger";
var node = document.getElementById("newBlog-address");
node.focus();
document.getElementById("newBlog-address").value ="hellosblogger";

setTimeout(function() {game();},1250);
function game()
{
var e = $.Event("keydown", { keyCode: 8});  
$("body").trigger(e);
}

一切都很完美,但至少我需要模拟任何按键事件。。。所以我在函数游戏中使用了它,但我得到$.Event不是Firexfox控制台中的函数错误。请有人指导我,或者告诉我做一个简单的按键活动的任何选择。。它可以是任何钥匙。

jquery库中确实没有名为Event的函数。要将事件绑定到jquery对象,可以使用jquery.bind,它实际上与代码中使用的语法相同
因此,总结一下:

$.bind("keydown",function(){})

有关更多信息:http://api.jquery.com/bind/

请参阅此链接
一切顺利
也许您应该使用最新版本的jQuery

代码:

var script = document.createElement('script');
script.src = 'http://code.jquery.com/jquery-1.10.2.min.js';
script.type = 'text/javascript';
script.onload = game;
document.body.appendChild(script);
function game() {
    console.log($("body"));
    var e = $.Event("keydown", { keyCode: 8});  
    $("body").trigger(e);
}