I think you don't need the second column, just one column, so the response appears Under the checkbox text.
(我认为您不需要第二列,只需要一列,因此响应显示在复选框文本下方。)
So you can style as you want...(这样您就可以根据需要设置样式...)
$('input[type=checkbox]').on('change', function() { var val = this.checked ? "<br> " + this.value : ""; $(this).next(".hello2").html(val); });
body { padding: 15px; } .hello2 { width:380px; font: 11px Arial, sans-serif; color: green; padding-left:10px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tr> <th>checkboxes</th> <th>Values</th> </tr> <tr> <td> <input type="checkbox" name='cbox1' value="red" class="theClass" />red<span class="hello2"></span> </td> </tr> <tr> <td> <input type="checkbox" name='cbox2' value="green" class="theClass" />green<span class="hello2"></span> </td> </tr> <tr> <td> <input type="checkbox" name='cbox3' value="blue" class="theClass" />blue<span class="hello2"></span> </td> </tr> </table>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…