<small id='VkzpS'></small><noframes id='VkzpS'>

  • <legend id='VkzpS'><style id='VkzpS'><dir id='VkzpS'><q id='VkzpS'></q></dir></style></legend>
    • <bdo id='VkzpS'></bdo><ul id='VkzpS'></ul>

        <i id='VkzpS'><tr id='VkzpS'><dt id='VkzpS'><q id='VkzpS'><span id='VkzpS'><b id='VkzpS'><form id='VkzpS'><ins id='VkzpS'></ins><ul id='VkzpS'></ul><sub id='VkzpS'></sub></form><legend id='VkzpS'></legend><bdo id='VkzpS'><pre id='VkzpS'><center id='VkzpS'></center></pre></bdo></b><th id='VkzpS'></th></span></q></dt></tr></i><div id='VkzpS'><tfoot id='VkzpS'></tfoot><dl id='VkzpS'><fieldset id='VkzpS'></fieldset></dl></div>

      1. <tfoot id='VkzpS'></tfoot>

        Greasemonkey 更改表单中单选按钮的值?

        时间:2023-10-21
        <i id='hcQeL'><tr id='hcQeL'><dt id='hcQeL'><q id='hcQeL'><span id='hcQeL'><b id='hcQeL'><form id='hcQeL'><ins id='hcQeL'></ins><ul id='hcQeL'></ul><sub id='hcQeL'></sub></form><legend id='hcQeL'></legend><bdo id='hcQeL'><pre id='hcQeL'><center id='hcQeL'></center></pre></bdo></b><th id='hcQeL'></th></span></q></dt></tr></i><div id='hcQeL'><tfoot id='hcQeL'></tfoot><dl id='hcQeL'><fieldset id='hcQeL'></fieldset></dl></div>
        • <tfoot id='hcQeL'></tfoot>

          <small id='hcQeL'></small><noframes id='hcQeL'>

          • <bdo id='hcQeL'></bdo><ul id='hcQeL'></ul>

                <tbody id='hcQeL'></tbody>
                <legend id='hcQeL'><style id='hcQeL'><dir id='hcQeL'><q id='hcQeL'></q></dir></style></legend>

                • 本文介绍了Greasemonkey 更改表单中单选按钮的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在编写 Greasemonkey/Tampermonkey 脚本,我需要根据单选控件的名称和值打开单选按钮.

                  I am writing a Greasemonkey/Tampermonkey script and I need to turn on radio buttons depending on the name and value of the radio control.

                  看起来是这样的:

                  <input type="radio" name="11" value="XXX" class="radio">
                  <input type="radio" name="11" value="zzzz" class="radio">
                  

                  所以我想设置那些名称为 11 且值为 zzzz 的按钮进行检查.

                  So I want to set those buttons that have name of 11 and a value of zzzz to be checked.

                  推荐答案

                  当您使用 jQuery 时,这非常容易.这是一个完整的脚本:

                  This is super easy when you use jQuery. Here's a complete script:

                  // ==UserScript==
                  // @name     _Radio button check
                  // @include  http://YOUR_SITE/YOUR_PATH/*
                  // @require  http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/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.
                  */
                  $("input[name='11'][value='zzzz']").prop ('checked', true);
                  

                  input[name='11'][value='zzzz'] jQuery 选择器获取所有具有 initialzzzz,但前提是它们位于具有 name="11" 的单选按钮组中.

                  The input[name='11'][value='zzzz'] jQuery selector gets all <input>s that have the initial value zzzz, but only if they are in the group of radio buttons with name="11".

                  参考:

                  • jQuery
                  • jQuery 选择器文档
                  • jQuery .prop()

                  重要:  以上方法适用于大多数页面,但在 AJAX 驱动的页面上,您通常需要使用 AJAX 感知技术.这是因为 Greasemonkey 脚本将在您选中复选框之前运行关心已加载.

                  Important:   The above works on most pages but, on AJAX-driven pages, you often need to use AJAX-aware techniques. This is because the Greasemonkey script will run before the checkbox you care about is loaded.

                  解决此问题的一种方法是使用 waitForKeyElements 实用程序.像这样:

                  One way to deal with this is with the waitForKeyElements utility. Like so:

                  // ==UserScript==
                  // @name     _Radio button check
                  // @include  http://YOUR_SITE/YOUR_PATH/*
                  // @require  http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/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[name='11'][value='zzzz']", selectRadioButton, true);
                  
                  function selectRadioButton (jNode) {
                      jNode.prop ('checked', true);
                  }
                  

                  <小时><小时><小时>

                  旧答案是最先进的":) 当问题被问到时:




                  Old answer that was "state of the art" :) back when the question was asked:

                  // ==UserScript==
                  // @name            _Radio button check
                  // @include         http://YOUR_SITE/YOUR_PATH/*
                  // @require         http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
                  // ==/UserScript==
                  
                  $("input[name='11'][value='zzzz']").attr ("checked", "checked");
                  

                  这篇关于Greasemonkey 更改表单中单选按钮的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 jQuery 计算单选按钮值的总和? 下一篇:HTML/CSS 中的单选/复选框对齐

                  相关文章

                      <tfoot id='JKLg3'></tfoot>
                      <i id='JKLg3'><tr id='JKLg3'><dt id='JKLg3'><q id='JKLg3'><span id='JKLg3'><b id='JKLg3'><form id='JKLg3'><ins id='JKLg3'></ins><ul id='JKLg3'></ul><sub id='JKLg3'></sub></form><legend id='JKLg3'></legend><bdo id='JKLg3'><pre id='JKLg3'><center id='JKLg3'></center></pre></bdo></b><th id='JKLg3'></th></span></q></dt></tr></i><div id='JKLg3'><tfoot id='JKLg3'></tfoot><dl id='JKLg3'><fieldset id='JKLg3'></fieldset></dl></div>

                      <legend id='JKLg3'><style id='JKLg3'><dir id='JKLg3'><q id='JKLg3'></q></dir></style></legend>
                        <bdo id='JKLg3'></bdo><ul id='JKLg3'></ul>
                    1. <small id='JKLg3'></small><noframes id='JKLg3'>