tableの入力画面で、例えばradioボタンの選択状況によって、下のtr要素の表示・非表示を変えたいとする
<table> <tr> <th> hpscript </th> <td> <input type="radio" name="a" value="y" checked>yes <input type="radio" name="a" value="n">no </td> </tr> <tr> <th> タイトル1 </th> <td> コンテンツ1 </td> </tr> </table>
これをVue.jsのv-on:${}で実装しようとしたが、上手く行かない
<table>
<div id="app">
<tr>
<th>
hpscript
</th>
<td>
<input type="radio" name="a" v-on:change="handler" value="y" checked>yes
<input type="radio" name="a" v-on:change="handler" value="n">no
</td>
</tr>
<div v-if="show">
<tr>
<th>
タイトル1
</th>
<td>
コンテンツ1
</td>
</tr>
</div>
</div>
</table>
<script>
new Vue({
el: '#app',
data: {
show: true
},
methods: {
handler: function(event){
if(event.target.value === 'y'){
this.show = true
} else {
this.show = false
}
}
}
})
</script>
ガッテム。結局、on.changeで実装することに。
<table>
<tr>
<th>
hpscript
</th>
<td>
<input type="radio" name="a" value="y" checked>yes
<input type="radio" name="a" value="n">no
</td>
</tr>
<tr class="changeterm displaynone">
<th>
タイトル1
</th>
<td>
コンテンツ1
</td>
</tr>
</table>
<script>
$('input[name=a]').on('change', function(){
if($('.changeterm').hasClass('displaynone')){
$('.changeterm').removeClass('displaynone');
} else {
$('.changeterm').addClass('displaynone');
}
});
</script>
.displaynone {
display:none;
}
なんでtableでVue.jsのv-onだと上手く行かないのかよくわからない。。
教えて欲しい。。🤖