使用表格中的复选框显示和隐藏项目 [英] Showing and hiding items using checkboxes in a table
问题描述
大家好,
希望这是一个非常简单明了的问题!
我有一个HTML表格,例如
Hi all,
Hopefully this is quite a straight forward and simple question!
I have a HTML table e.g
<table width="229" border="1">
<tr>
<th width="191" id="0"> </th>
<th width="22" scope="col"> <input type="checkbox" name="newsletter" value="0" id="0"></th>
</tr>
<tr>
<td id="1"> </td>
<td><input type="checkbox" name="newsletter" value="1" id = "1"></td>
</tr>
<tr>
<td id="2"> </td>
<td><input type="checkbox" name="newsletter" value="2" id = "2"></td>
</tr>
<tr>
<td id="3"> </td>
<td><input type="checkbox" name="newsletter" value="3" id = "3"></td>
</tr>
</table>
用户单击相关的复选框我希望它旁边的单元格显示一些文本(它最终将包含一个下拉框,我想开始简单的冷杉t)...
如果用户只点击一个框,我创建的代码就可以工作,如果用户选择多个框就没用了。
var checkedOn = function(){
var n = $(input:checked)。length; //获取所选框的数量
var k = $(input:checked)。val(); //获取所选框的值(仅限第一个)
$(#+ k).text(k); //在相应的单元格中显示它
};
如果有人能给我任何帮助,那就太棒了!
非常感谢
When a user clicks the relevant checkbox I would like the cell next to it to show some text (it will eventually contain a drop down box, i thought start simple first)...
The code I created works if a user clicks only one box, this is no use if they select more than one box.
var checkedOn = function() {
var n = $( "input:checked" ).length; //Gets the number of selected boxes
var k = $("input:checked").val(); //Gets the value of the selected box (only the first one)
$("#"+k).text(k); //Displays it in the corresponding cell
};
If anybody can give me any help that would be great!
Many thanks
推荐答案
(input:checked)。length; //获取所选框的数量
var k =
( "input:checked" ).length; //Gets the number of selected boxes
var k =
(input:checked)。val(); //获取所选框的值(仅第一个)
("input:checked").val(); //Gets the value of the selected box (only the first one)
(#+ k).text(k); //在相应的单元格中显示它
};
如果有人能给我任何帮助,那就太棒了!
非常感谢
("#"+k).text(k); //Displays it in the corresponding cell
};
If anybody can give me any help that would be great!
Many thanks
这篇关于使用表格中的复选框显示和隐藏项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!