我正在嘗試在網頁中執行此代碼,如果檢測到按下 shift 鍵,它將提醒“shift”。
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match ...
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
alert('Loaded!');
var $ = window.jQuery;
$(document).keypress(function(e) {
if (e.which == 16) {
alert("shift");
}
});
})();
程式提示“已加載!” 但是當我按下換檔按鈕時不會提醒“換檔”。誰能幫我弄清楚問題出在哪里?
uj5u.com熱心網友回復:
該keypress事件已被棄用。請改用keydown事件。
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://stackoverflow.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
alert('Loaded!');
var $ = window.jQuery;
$(document).on('keydown', function(e) {
if (e.which == 16) {
alert("shift");
}
});
})();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/463708.html
標籤:javascript jQuery 篡改猴子
