2013-03-06 61 views
0

我有这样的HTML:验证输入电台的jQuery不工作值检查

<div class="produtoListaDescTamanho"> 
    <label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="9"><b>Frango Teriaky R$ 6.00&nbsp;&nbsp;&nbsp;</b></label> 
    <label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="8"><b>Camarão R$ 6.00&nbsp;&nbsp;&nbsp;</b></label> 
    <label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="7"><b>Salmão e Queijo Qualho R$ 6.00&nbsp;&nbsp;&nbsp;</b></label> 
    <label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="6"><b>Salmão R$ 6.00&nbsp;&nbsp;&nbsp;</b></label> 
    <label class="textoPadrao pequeno laranja"><input type="radio" name="tamanho-324" value="10"><b>Mignom R$ 6.00&nbsp;&nbsp;&nbsp;</b></label><br><br> 
</div> 

和这个jQuery不工作的验证是与jQuery,VAR = tamanho未定义输入无线电。 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

+3

'live'不赞成使用'on'代替.. – Deadlock 2013-03-06 11:35:40

+0

尝试'$( '输入[名称= “tamanho - '+ this.id +'”]:检查')'(即,围绕name属性的值添加双引号)。 – nnnnnn 2013-03-06 11:37:05

+0

元素“”不存在。你的选择器是错误的。使用'input [name ='tamanho-324']'而不是 – 2013-03-06 11:38:11

回答

1

尝试在jQuery的这种使用名称选择。

var tamanho = $('input:radio[name="tamanho-324"]:checked').val(); 
+0

Tks,正在... – 2013-03-06 11:56:30

+0

@ user1697145,欢迎亲爱的.. – 2013-03-06 11:57:44

0
repalce 

temp = document.getElementsByName('tamanho-'+this.id); 
$(temp).removeAttr('checked'); 
$(temp).attr('previousValue', false); 


with 

$('#tamanho-'+this.id).each(function(index) { 
this.removeAttr('checked'); 
this.attr('previousValue', false); 
});