2013-03-18 67 views
2

供应商的网络应用程序要求我选择收音机组中的缩略图,然后点击保存,我必须执行此操作超过300次。他们没有让单选按钮内容可点击的风格。我认为通用汽车会允许我这样做,但我对如何编写剧本感到迷茫。如果我可以让单选按钮继续并启动提交按钮,那就更好了。这里的代码:使用Greasemonkey添加表单标签

<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="" /> 

任何人都可以指出我在正确的方向吗?谢谢!

回答

1

要添加标签,请使用jQueryjQuery's .wrap() function。像这样的东西应该这样做:

$("input[name='selectimageid']").wrap ('<label></label>'); 

然而,我假设你想要的缩略图是标签的点击部分。 A 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>'); 
}); 
+0

完美的工作。谢谢!!!我不能自己解决这个问题,而不是在我的最后期限之内。再次感谢。 – Jordan 2013-03-19 15:17:39

+0

不客气!乐意效劳。 – 2013-03-19 20:49:31