2011-11-28 41 views
0

我有一張帶有選擇輸入單選按鈕的表格。無線輸入按鈕2具有值=「P2」或「P1」和以S開始的其餘部分的值作爲你可以看到下面基於無線電值更改鏈接按鈕名稱

<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="P2"/> 
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="P1"/> 


<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S111"/> 
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S112"/> 
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S131"/> 
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S132"/> 
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(true);" type="radio" value="S121"/> 
<input id="test" name="purchaseChoice" class="radio" onclick="togglePrices(false);" type="radio" value="S122"/> 
<a href='javascript: submitform("subsOptionform")' tabindex="14" class="right button blue">Subscribe</a> 

我想有從訂閱的鏈路變化的標籤當選擇2個第一個單選按鈕時購買學分。

任何幫助表示讚賞。

感謝

+0

你有完全相同的ID ** 8個**元素。祝你好運,以獲得任何工作。另外,你的代碼中沒有jQuery的舔。我會研究jQuery *做些什麼*然後嘗試重構你的代碼來使用它。 – Blender

+0

大聲笑@Blender他們看起來像90年代初的代碼。 – nolabel

+0

感謝您的回覆。基本上上面引用的代碼只是在瀏覽器上查看時複製的源代碼。有問題的頁面是用java開發的,並且最初使用html5和jQuery進行標記。事實上,我們桌面上的8個單選按鈕的呈現是通過jQuery實現的,以根據無線電選擇呈現不同的價格。我知道有一個特定的身份證沒有幫助。需要重新考慮爲什麼會有。 – gek

回答

1

首先,你需要將你input S的標識更改爲唯一值或沒有工作有保證。

接下來,嘗試把這個在您的$(document).ready(function(){

$('.radio').change(function(){ 
    if($(this).attr('value') === 'P1' || $(this).attr('value') === 'P2'){ 
     $('.blue').text('Buy credits'); 
    }else{ 
     $('.blue').text('Subscribe'); 
    } 
}); 
+0

如果他在該頁面上具有多於$('。blue')'的實例,則腳本將無法按預期工作。 – Blazemonger

+0

@ mblase75沒錯,但他並沒有給我太多的工作(即ID是最優的)。 – wanovak

+0

嗨,大家好,謝謝你的回覆。我可以問你爲什麼使用.blue?我們可以創建其他課程嗎?以及鏈接html的外觀如何? – gek