【发布时间】:2013-02-21 04:20:36
【问题描述】:
我有这个 HTML:
<div class="produtoListaDescTamanho">
<label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="9"><b>Frango Teriaky R$ 6.00 </b></label>
<label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="8"><b>Camarão R$ 6.00 </b></label>
<label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="7"><b>Salmão e Queijo Qualho R$ 6.00 </b></label>
<label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="6"><b>Salmão R$ 6.00 </b></label>
<label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="10"><b>Mignom R$ 6.00 </b></label><br><br>
</div>
并且这个 Jquery 不能用于验证是带有 Jquery 的输入单选,var tamanho = undefined。 jQuery代码:
$(document).ready(function(){$('.produtoAddCarinho').live("click",(function(){
alert(this.id);
var tamanho = $('tamanho-324:checked').val(); // or $('input[name=tamanho-'+this.id+']:checked', '#tabela_geral').val();
var produto = document.getElementById('desc-'+this.id).innerHTML;
if (tamanho == undefined)
{
$().toastmessage('showErrorToast', "Selecione o tamanho, para adiconar o produto <br><br>" + produto );
}
else
{
Inserir(this.id, tamanho, produto);
};
temp = document.getElementsByName('tamanho-'+this.id);
$(temp ).removeAttr('checked');
$(temp ).attr('previousValue', false);
}))});
tks
【问题讨论】:
-
live已弃用,请改用on.. -
试试
$('input[name="tamanho-'+this.id+'"]:checked')(即,在名称属性的值周围添加双引号)。 -
元素
<tamanho-324>不存在。你的选择器是错误的。请改用input[name='tamanho-324'] -
这与jquery-validate插件无关。请在标记时更加小心。谢谢。已编辑。
标签: jquery input validation radio