vendor 的网络应用程序要求我在单选组中选择一个缩略图,然后点击保存,我必须这样做 300 多次。而且他们没有礼貌地让单选按钮内容可点击。我以为 GM 会允许我这样做,但我不知道如何编写脚本。如果我能让单选按钮继续并触发提交按钮,那就更好了。这是代码:
<div id="image1" class="image_selection">
<input type="radio" id="" class="" name="selectimageid" value="1"/>
<img id="1" class="thumb" src="/images/thumb1.jpg" />
</div>
<div id="image2" class="image_selection">
<input type="radio" id="" class="" name="selectimageid" value="2"/>
<img id="2" class="thumb" src="/images/thumb2.jpg" />
</div>
<input type="submit" id="" class="save_button" name="" value="" />
谁能指出我正确的方向?谢谢!
最佳答案
要添加标签,请使用 jQuery和 jQuery's .wrap()
function .应该这样做:
$("input[name='selectimageid']").wrap ('<label></label>');
但是,我假设您希望缩略图成为标签的可点击部分。一个完整的 Greasemonkey 脚本是:
// ==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
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
var imgRadioBtns = $("input[name='selectimageid']");
imgRadioBtns.each ( function () {
var radBtn = $(this);
var toWrap = radBtn.nextAll ("img.thumb").addBack ();
toWrap.wrapAll ('<label></label>');
} );
关于javascript - 使用 Greasemonkey 添加表单标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15486420/