如何设置两个输入和一个按钮? [英] How to set two inputs and ungrey a button?

查看:85
本文介绍了如何设置两个输入和一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使用Greasemonkey在网页中自动填写用户名/密码的方法.

I'm looking for a way to automatically fill in a username/password in a webpage using Greasemonkey.

这两个标签是输入,它们没有ID,但是它们是页面中仅有的两个输入,当按下登录"按钮时,它们会出现.

The two tags are inputs, they have no ID but they're the only two inputs in the page, which appear when a 'log in' button is pressed.

我是Greasemonkey(和javascript)的初学者,我想知道如何才能等待这两个输入出现.
然后有两个按钮,确定"和取消"按钮. 确定"按钮呈灰色,并且使用element0.value="password"设置输入不会使按钮变灰.

I am a beginner in Greasemonkey (and javascript) and I was wondering how I could wait for these two inputs to appear.
Then there's two buttons, an 'ok' and a 'cancel' button. The 'ok' button is greyed, and setting the inputs with element0.value="password" doesn't ungrey the button.

如何使用javascript使其变色?

How can I ungrey it using javascript?

推荐答案

问题缺少请求的HTML和必需的HTML ,但是通常,您会使用.

The question lacks the requested and required HTML, but in general, you would use techniques from "Choosing and activating the right controls on an AJAX-driven site".

类似的东西:

// ==UserScript==
// @name     _YOUR_SCRIPT_NAME
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.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.
*/

waitForKeyElements ("input[type='password']", logIn);

function logIn (jNode) {
    var inputs  = $("input");

    //-- DO NOT HARDCODE LOGIN CREDENTIALS IN A SCRIPT!
    $(inputs[0]).val ("username");
    $(inputs[1]).val ("password");

    //-- Might need to trigger a change or mouse event here.

    waitForKeyElements (
        "JQUERY SELECTOR FOR THE OK BUTTON IN THE ACTIVE STATE",
        clickOK_Btn
    );
}

function clickOK_Btn (jNode) {
    triggerMouseEvent (jNode[0], "click");
}

function triggerMouseEvent (node, eventType) {
    var clickEvent = document.createEvent('MouseEvents');
    clickEvent.initEvent (eventType, true, true);
    node.dispatchEvent (clickEvent);
}



但不要对登录凭据进行硬编码.使用敏感信息框架.



But do not hardcode login credentials. Use a sensitive information framework.

这篇关于如何设置两个输入和一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆