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

      <tfoot id='Fb2Fc'></tfoot>

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

      1. 如何使用 Greasemonkey 自动选择特定的单选按钮?

        How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)

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

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

          <tbody id='NJCte'></tbody>
          • <tfoot id='NJCte'></tfoot>
              <bdo id='NJCte'></bdo><ul id='NJCte'></ul>

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

                  问题描述

                  我想用 Greasemonkey 自动回答问题.我有问题和答案,但如何选择它们?

                  I want to automatically answer questions with Greasemonkey. I have the questions and answers, but how can select them?

                  这是 HTML:

                  <div class="vito_form_q">
                      <div class="vito_form_title_min_no">
                          <span id="ContentPlaceHolder1_lblquestionNo">8</span>
                      </div>
                      <div class="vito_form_title_min">
                          <span id="ContentPlaceHolder1_lblquestion">Which sport is not playing with the ball?</span>
                      </div>
                      <div class="clearfloat"></div>
                      <div class="meter orange nostripes"><span style="width: 100%"></span></div>
                      <div class="quest">
                          <table id="rbAnswer" class="q1">
                          <tr><td>
                              <input id="rbAnswer_0" type="radio" name="ctl00$ContentPlaceHolder1$rbAnswer" value="157"/><label for="rbAnswer_0">Handball</label>
                          </td></tr>
                          <tr><td>
                              <input id="rbAnswer_1" type="radio" name="ctl00$ContentPlaceHolder1$rbAnswer" value="158"/><label for="rbAnswer_1">Basketball</label>
                          </td></tr>
                          <tr><td>
                              <input id="rbAnswer_2" type="radio" name="ctl00$ContentPlaceHolder1$rbAnswer" value="159"/><label for="rbAnswer_2">Football</label>
                          </td></tr>
                          <tr><td>
                              <input id="rbAnswer_3" type="radio" name="ctl00$ContentPlaceHolder1$rbAnswer" value="160"/><label for="rbAnswer_3">Fencing</label>
                          </td></tr>
                  


                  例如,对于这个问题:

                      <span id="ContentPlaceHolder1_lblquestion">Which sport is not playing with the ball?</span>
                  

                  选择答案:

                  <td>
                      <input id="rbAnswer_3" type="radio" name="ctl00$ContentPlaceHolder1$rbAnswer" value="160" />
                      <label for="rbAnswer_3">Fencing</label>
                  

                  如何使用 Greasemonkey 做到这一点?

                  How can I do this with Greasemonkey?

                  推荐答案

                  制作一系列问题和答案,如下所示:

                  Make an array of questions and answers, like so:

                  var answerKey   = [
                        { q: "sport is not playing with the ball", a: "Fencing" }
                      , { q: "Best SciFi franchise",               a: "Star Trek" }
                      , { q: "Most badass monster",                a: "Bun-Bun" }
                      , { q: "Most toxic chemical in this list",   a: "Mountain Dew" }
                      // etc.
                  ];
                  


                  然后将此行添加到 Greasemonkey 脚本的元数据块:

                  Then add this line to the Metadata Block of your Greasemonkey script:

                  // @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
                  


                  然后,使用 jQuery 的强大功能,您的脚本可以使用以下代码检查正确的单选按钮:


                  Then, using the awesome power of jQuery, your script can check the right radio buttons with the following code:

                  (在 jsFiddle 上查看底层代码的演示.)p>

                  var answerKey   = [
                        { q: "sport is not playing with the ball", a: "Fencing" }
                      , { q: "Best SciFi franchise", a: "Star Trek" }
                      , { q: "Most badass monster", a: "Bun-Bun" }
                      , { q: "Most toxic chemical in this list", a: "Mountain Dew" }
                      // etc.
                  ];
                  
                  //--- Loop through the question(s) on the page and answer then if possible.
                  var questionTxt = $("div div.vito_form_title_min span[id$='question']");
                  
                  questionTxt.each ( function () {
                      var bFoundAnswer    = false;
                      var answerTxt       = getAnswer (this.textContent);
                      if (answerTxt) {
                          //--- We have the answer text, now find the matching radio button and select it.
                          var ansForThisQ     = $(this).parent (). nextAll ("div.quest").find ("label");
                  
                          ansForThisQ.each ( function () {
                              var zRegExp     = new RegExp (answerTxt, 'i');
                              if (zRegExp.test (this.textContent) ) {
                                  bFoundAnswer    = true;
                                  var label       = $(this);
                                  var radioButt   = $("#" + label.prop ("for") );
                                  radioButt.prop  ("checked", "checked");
                                  label.css       ("background", "lime");
                                  return false;   // End loop
                              }
                          } );
                      }
                      else {
                          alert ("I don't know how to answer: '" + this.textContent + "'");
                          $(this).css ("background", "pink");
                      }
                      if ( answerTxt  &&  ! bFoundAnswer) {
                          alert ("The page does not have the specified answer for the question: '" + this.textContent + "'");
                          $(this).css ("background", "pink");
                      }
                  } );
                  
                  function getAnswer (questionText) {
                      for (var J = answerKey.length - 1;  J >= 0;  --J) {
                          var zRegExp = new RegExp (answerKey[J].q, 'i');
                  
                          if (zRegExp.test (questionText) )
                              return answerKey[J].a;
                      }
                      return null;
                  }
                  

                  这篇关于如何使用 Greasemonkey 自动选择特定的单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  keeping radio buttons checked after form submit(表单提交后保持选中单选按钮)
                  Styling radio button - not work in IE and Firefox(样式单选按钮 - 在 IE 和 Firefox 中不起作用)
                  Bootstrap radio button quot;checkedquot; flag(Bootstrap 单选按钮“已选中旗帜)
                  Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                  Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                  JavaScript radio button confirmation(JavaScript 单选按钮确认)

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

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

                        <tbody id='rELfz'></tbody>
                          <tfoot id='rELfz'></tfoot>
                            <bdo id='rELfz'></bdo><ul id='rELfz'></ul>