Javascript 如何添加一个";onblur";使用Greasemonkey的文本框的处理程序?

Javascript 如何添加一个";onblur";使用Greasemonkey的文本框的处理程序?,javascript,dom-events,greasemonkey,Javascript,Dom Events,Greasemonkey,我有这个代码,它在测试页面中运行良好 Javascript: function myFunction() { var x = document.getElementById("tarea"), nameInput = document.getElementById('name'), classInput = document.getElementById('class'); var lines = x.value.split(

我有这个代码,它在测试页面中运行良好

Javascript:

function myFunction() {
    var x = document.getElementById("tarea"),
        nameInput = document.getElementById('name'),
        classInput = document.getElementById('class');

    var lines = x.value.split('\n');
    var name = lines[0].substring(5);
    var grade = lines[1].substring(6);

    nameInput.value = name;
    classInput.value = grade;
}
HTML:


现在,我想使用Greasemonkey将
onblur
功能添加到先前存在的页面

但是,我不知道如何在Greasemonkey中使用
onblur
Javascript事件。我已经用
onblur

使用(纯javascript)或(更健壮的方法)搜索了Greasemonkey,但找不到任何例子

普通JS:

// ==UserScript==
// @name     _YOUR_SCRIPT_NAME
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant    GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/

var targInput = document.getElementById ("tarea");
targInput.addEventListener ("blur", myFunction, false);

function myFunction () {
    ... ...
}

jQuery(推荐),请注意
@require

// ==UserScript==
// @name     _YOUR_SCRIPT_NAME
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/

$(document).on ("blur", "#tarea", myFunction);

function myFunction () {
    ... ...
}
// ==UserScript==
// @name     _YOUR_SCRIPT_NAME
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @grant    GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/

$(document).on ("blur", "#tarea", myFunction);

function myFunction () {
    ... ...
}