2013-03-06 98 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); 
});