2013-01-21 101 views
0

我不知道JavaScript,因此無論如何這可能會出現在錯誤的軌道上。 我有可以通過單選按鈕選擇的運輸方式。如果選擇某種運輸方式,我嘗試創建警報,但無線電價值會根據可用的運輸選項進行更改。如果選中單選按鈕,則發出警報

<label id="shippingMethod"><input type="radio" name="selectedShippingMethod" id="shippingCheck" value="5"> <span class="ShipperName">Collect Shipping</span> <em class="ShipperPrice ProductPrice">$0.00</em></label> 

這裏是報警代碼我試圖使用

$(document).ready(function(){ 
    $('input:radio[name="selectedShippingMethod"]').change(function() { 
     if ($(this).val() == '5'){ 
      alert('ALERT TEXT TO POPUP'); 
     } 
    }); 
}); 

有沒有一種方法,我可以把它觸發基於ShipperName「收集送貨」,而不是無線電值警報,或者是否有更好的方法來做到這一點開始。

+0

請問你實際的代碼只有一個單選按鈕? –

+0

不,它有從1到6的任何地方。最好是,我希望它嚴格地根據選定廣播旁邊的文本調用警報,因爲我無法控制它後面的代碼,並且可以更改它由購物車公司提供。 – Chad

+0

所以你想「提醒」範圍內的文字? –

回答

1
$(document).ready(function() { 

    var $radios = $('input:radio[name="selectedShippingMethod"]'); 

    $radios.change(function() { 
     var $selected = $radios.filter(':checked'); 
     if ($selected.val() == 5) { 
      alert($selected.parent().text()); 
     } 
    }); 
}); 
0

約瑟夫西爾伯,我建議的唯一改變是設置警報爲「收集航運」每OPs原始目標。

你的功能幫助我有類似的解決方案我一直在尋找(謝謝!)

$(document).ready(function() { 
    var $radios = $('input:radio[name="selectedShippingMethod"]'); 
    $radios.change(function() { 
    var $selected = $radios.filter(':checked'); 
    if ($selected.val() == 5) { 
     alert("Collect Shipping"); 
     } 
    }); 
}); 
相關問題