我不知道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 :(得分: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() );
}
});
});
答案 1 :(得分:0)
约瑟夫·西尔伯,我建议的唯一改变是根据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" );
}
});
});