Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 尝试将jquery加载到脚本中_Javascript_Jquery_Tampermonkey - Fatal编程技术网

Javascript 尝试将jquery加载到脚本中

Javascript 尝试将jquery加载到脚本中,javascript,jquery,tampermonkey,Javascript,Jquery,Tampermonkey,我正在写一个脚本,在登录页面加载时登录到我的大学网络 代码如下所示 // ==UserScript== // @name My Fancy New Userscript // @namespace http://use.i.E.your.homepage/ // @version 0.1 // @description enter something useful // @match <College login page> // @copyright

我正在写一个脚本,在登录页面加载时登录到我的大学网络

代码如下所示

// ==UserScript==
// @name       My Fancy New Userscript
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  enter something useful
// @match      <College login page>
// @copyright  2012+, You
// ==/UserScript==    
$(document).ready(function() {

    var usr=document.getElementsByName("username");

    var pass = document.getElementByName("password");

    usr.value="usrname";    
    pass.value="password";    

    var submitButton = document.querySelector ('input[type="submit"][value="Login"]');

    var clickEvent  = document.createEvent ('MouseEvents');

    clickEvent.initEvent ('click', true, true);

    submitButton.dispatchEvent (clickEvent);

    });

有人能告诉我这里发生了什么吗?

您需要在用户脚本头中有一个
@require
来加载jQuery。比如:

// @require http://code.jquery.com/jquery-3.4.1.min.js
(从中选择您想要的版本)

供未来的谷歌用户使用

如果您使用了上述方法,但jQuery似乎仍然没有被脚本加载,请尝试查看空格,并尝试将缩进与标题的其余部分匹配。显然,压痕很重要

故障:

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://stackoverflow.com/*
// @require http://code.jquery.com/jquery-3.4.1.min.js 
// @grant        none
// ==/UserScript==
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://stackoverflow.com/*
// @require      http://code.jquery.com/jquery-3.4.1.min.js 
// @grant        none
// ==/UserScript==
正确:

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://stackoverflow.com/*
// @require http://code.jquery.com/jquery-3.4.1.min.js 
// @grant        none
// ==/UserScript==
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://stackoverflow.com/*
// @require      http://code.jquery.com/jquery-3.4.1.min.js 
// @grant        none
// ==/UserScript==

请不要使用
jquery-latest
。请注意,这可能会干扰页面本身对
$
@Owen的定义,我们将如何处理that@Menasheh。还请注意,页面自己的jQuery可能会出现,并对
@require
d版本造成冲击<代码>无冲突也会有帮助。