2013-03-18 50 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