如何从输入类型=“按钮”复制和粘贴值?

发布于 2024-09-18 12:33:07 字数 553 浏览 4 评论 0原文

我必须从很多页面复制并粘贴输入类型=“按钮”的值(即值=“1.25”,值=“3.50”)。是否可以使用jquery或greasemonkey?

<td>
    <input type="button" onmouseout="btnGiocataOut(this)" onmouseover="btnGiocataOver(this)" onclick="aggiungiScommessa(6659, 12, 22, 1, 125)" value="1.25" class="ris">
</td>
<td class="valore" colspan="1">Over</td>
<td>
    <input type="button" onmouseout="btnGiocataOut(this)" onmouseover="btnGiocataOver(this)" onclick="aggiungiScommessa(6659, 12, 22, 2, 350)" value="3.50" class="ris">
</td>

I have to copy and paste the values of input type="button" (ie value="1.25", value="3.50") from a lot of pages. Is it possible using jquery or greasemonkey?

<td>
    <input type="button" onmouseout="btnGiocataOut(this)" onmouseover="btnGiocataOver(this)" onclick="aggiungiScommessa(6659, 12, 22, 1, 125)" value="1.25" class="ris">
</td>
<td class="valore" colspan="1">Over</td>
<td>
    <input type="button" onmouseout="btnGiocataOut(this)" onmouseover="btnGiocataOver(this)" onclick="aggiungiScommessa(6659, 12, 22, 2, 350)" value="3.50" class="ris">
</td>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑脸一如从前 2024-09-25 12:33:07

http://www.learningjquery.com/2006/12/jquerify-bookmarklet

JQuery 书签 - 然后在 firebug 控制台中:

$("input[type='button']").each(function() { console.log($(this).val()); }); 

http://www.learningjquery.com/2006/12/jquerify-bookmarklet

JQuery bookmarklet - and then in firebug console:

$("input[type='button']").each(function() { console.log($(this).val()); }); 
╰つ倒转 2024-09-25 12:33:07

是的,如果您想自动获取按钮值,而不需要在每个页面上使用 Firebug,Greasemonkey 可以做到这一点。

这是一个可以帮助您入门的脚本。请务必调整 @include 语句以匹配您的目标网站。

//
// ==UserScript==
// @name            Button value grabber
// @namespace       Gambling
// @description     Grabs button values.
// @include         *
// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
//

$(document).ready (Greasemonkey_main);

function Greasemonkey_main ()
{
    /*--- Create a container div and area for the values.  It will be styled and
        postioned with CSS.
    */
    $("body").append
    (
          '<div id="GM_PopUpDiv">'
        +   '<h3>Button Values on this page:</h3>'
        +   '<form id="GM_ContForm"><textarea id="GM_BtnValues"><\/textarea><\/form>'
        + '<\/div>'
    );

    //--- Make it almost invisible when not moused over.
    $('#GM_PopUpDiv').hover
    (
        function () { $(this).stop (true, false).fadeTo (50, 1); },
        function () { $(this).stop (true, false).fadeTo (900, 0.15); }
    );

    /*--- Copy the button values.   Fine-tune the selector to taste.
        For example, input.ris[type='button']
    */
    var NumRows = 0;
    var BtnVals = $("input[type='button']").map (function(J) {
                    NumRows = J;
                    return this.value;
                } ).get ().join ('\n')
                ;

    /*--- Paste the values into the textarea and adjust the height to the data
        (within the min/max set by CSS, below).
    */
    $("#GM_BtnValues").text (BtnVals). css ('height', NumRows + 4 + 'em');
}


//--- This is just CSS to make the new stuff look "purty".
GM_addStyle
(
   '#GM_PopUpDiv                                                    \
    {                                                               \
        font-size:              16px;                               \
        background:             wheat;                              \
        border:                 3px double #999999;                 \
        margin:                 5px;                                \
                                                                    \
        min-height:             100px;                              \
        min-width:              400px;                              \
        padding:                5px 20px;                           \
                                                                    \
        opacity:                0.15;                               \
        z-index:                1222;                               \
        position:               fixed;                              \
        top:                    0px;                                \
        left:                   0px;                                \
    }                                                               \
    #GM_PopUpDiv textarea                                           \
    {                                                               \
        font-size:              16px;                               \
        min-height:             6em;                                \
        max-height:             32em;                               \
        width:                  100%;                               \
        padding:                8px;                                \
        word-wrap:              normal;                             \
    }                                                               \
    #GM_PopUpDiv h3                                                 \
    {                                                               \
        font-size:              16px;                               \
        text-align:             left;                               \
        margin:                 0px;                                \
    }                                                               \
   '
);

Yes, if you want to grab button values automatically, without futzing with Firebug on every page, Greasemonkey can do that.

Here's a script that should get you started. Be sure to adjust the @include statements to match your target sites.

//
// ==UserScript==
// @name            Button value grabber
// @namespace       Gambling
// @description     Grabs button values.
// @include         *
// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
//

$(document).ready (Greasemonkey_main);

function Greasemonkey_main ()
{
    /*--- Create a container div and area for the values.  It will be styled and
        postioned with CSS.
    */
    $("body").append
    (
          '<div id="GM_PopUpDiv">'
        +   '<h3>Button Values on this page:</h3>'
        +   '<form id="GM_ContForm"><textarea id="GM_BtnValues"><\/textarea><\/form>'
        + '<\/div>'
    );

    //--- Make it almost invisible when not moused over.
    $('#GM_PopUpDiv').hover
    (
        function () { $(this).stop (true, false).fadeTo (50, 1); },
        function () { $(this).stop (true, false).fadeTo (900, 0.15); }
    );

    /*--- Copy the button values.   Fine-tune the selector to taste.
        For example, input.ris[type='button']
    */
    var NumRows = 0;
    var BtnVals = $("input[type='button']").map (function(J) {
                    NumRows = J;
                    return this.value;
                } ).get ().join ('\n')
                ;

    /*--- Paste the values into the textarea and adjust the height to the data
        (within the min/max set by CSS, below).
    */
    $("#GM_BtnValues").text (BtnVals). css ('height', NumRows + 4 + 'em');
}


//--- This is just CSS to make the new stuff look "purty".
GM_addStyle
(
   '#GM_PopUpDiv                                                    \
    {                                                               \
        font-size:              16px;                               \
        background:             wheat;                              \
        border:                 3px double #999999;                 \
        margin:                 5px;                                \
                                                                    \
        min-height:             100px;                              \
        min-width:              400px;                              \
        padding:                5px 20px;                           \
                                                                    \
        opacity:                0.15;                               \
        z-index:                1222;                               \
        position:               fixed;                              \
        top:                    0px;                                \
        left:                   0px;                                \
    }                                                               \
    #GM_PopUpDiv textarea                                           \
    {                                                               \
        font-size:              16px;                               \
        min-height:             6em;                                \
        max-height:             32em;                               \
        width:                  100%;                               \
        padding:                8px;                                \
        word-wrap:              normal;                             \
    }                                                               \
    #GM_PopUpDiv h3                                                 \
    {                                                               \
        font-size:              16px;                               \
        text-align:             left;                               \
        margin:                 0px;                                \
    }                                                               \
   '
);
橙味迷妹 2024-09-25 12:33:07

我在这样的一次性情况下使用 Firebug 和 jQuery。如果需要,我会动态加载 jQuery: $('

I use Firebug and jQuery in one-off situations like this. I load jQuery dynamically if necessary: $('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" />').appendTo(document.body);. That goes in the Firebug console. Then I would use something like $('input').each(function() { console.log($(this).val()); });, and it would print out a list that I could easily copy. I would repet these steps for every page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文