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“收集运费”而不是无线电值触发警报,或者有更好的方法来开始这样做。

4

2 回答 2

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() );
        }
    });
});
于 2013-01-22T00:06:19.280 回答
0

Joseph Silber,我建议的唯一更改是根据 OP 的原始目标将警报设置为“收集运输”。

您的功能帮助我找到了我正在寻找的类似解决方案(谢谢!)

$(document).ready(function () {
  var $radios = $('input:radio[name="selectedShippingMethod"]');
  $radios.change(function () {
    var $selected = $radios.filter(':checked');
    if ( $selected.val() == 5 ) {
        alert("Collect Shipping" );
        }
    });
});
于 2016-02-13T16:37:14.847 回答