2016-06-21 2 views
0

これはなぜ機能しないのですか?私は、ユーザーが特定の入力要素にアクセスするのを防ぐために、表形式で表を表示および非表示にしようとしています。何をすべきか、ベストプラクティスは何かアドバイスしてください。ありがとうございました。 jQueryとHTMLへイム新しい:htmlの表はjqueryで動作しません

HTMLとjQuery:

$(document).ready(function(){ 
 
$('#table1').hide(); 
 
}); 
 

 
$('input[name="both"]').click(function(){ 
 
$('#table1').show(); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<p> 
 
<input type="radio" name="both" /> 
 
<label for="walk_in">Walk in</label> 
 
</p> 
 
<form> 
 
<table id="table1" name="table1"> 
 
    data1 
 
</table> 
 
<table id="table2" name="table2"> 
 
    data2 
 
</table> 
 

 
</form>

+0

私はここにdiv要素のように使用されたテーブルを参照してください。何か不足していますか? – Alexandre

答えて

0

試してみてください。

あなたがタグにあなたのテーブルのコンテンツを追加する必要があります。..

$(document).ready(function(){ 
 
$('#table1').hide(); 
 
}); 
 

 
$('input[name="both"]').click(function(){ 
 
$('#table1').show(); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
 
<p> 
 
<input type="radio" name="both" /> 
 
<label for="walk_in">Walk in</label> 
 
</p> 
 
<form> 
 
<table id="table1" name="table1"> 
 
    <tr><td> data1 </td></tr> 
 
</table> 
 
<table id="table2" name="table2"> 
 
    <tr><td> data2 </td></tr> 
 
</table> 
 

 
</form>

+1

閉じている 'tr'、' td'タグは間違った方法です – Pete

+0

は作品です、ありがとう –

0

私はその入力にIDを割り当てるとjQueryで要素に対処するためにそれを使用しようとする:

<input type="radio" id="my_input" name="both" /> 


$('#my_input').click(function(){ 
$('#table1').show(); 
}); 
関連する問題