
思路:通过 :checked 筛选 checkbox 选中项,然后进行遍历,利用节点关系获取到input对象,最后使用val()方法获取input的内容。实例演示如下:
1、HTML结构
<table>
<tr>
<td><input type="checkbox" name="test"></td>
<td><input type="text"></td><td><input type="text"></td>
</tr>
<tr>
<td><input type="checkbox" name="test"></td>
<td><input type="text"></td><td><input type="text"></td>
</tr>
</table>
<input type="button" value="确定">
2、jquery代码
$(function(){
$(":button")click(function() {
// 找到选中行的input
var ipts = $(":checkbox:checked")parents("tr")find("input:text");
// 遍历input并使用val()方法获取值
str = map(function() {return $(this)val();})get()join(", ");
alert(str);
});
});
Form1中: List<string> s = new List<string>();
foreach (Control o in thisControls)
{
if (o is CheckBox)
{
if (((CheckBox)o)Checked == true)
{
sAdd(thischeckBox1Text);
}
}
}
Form2 f = new Form2(s);
fShow();
Form2中重写构造函数:
public Form2()
{
InitializeComponent();
}
public Form2(List<string> lst)
{
InitializeComponent();
lst = s;
}
参考代码如下:
获取所有name为spCodeId的checkbox
var spCodesTemp = "";$('input:checkbox[name=spCodeId]:checked')each(function(i){
if(0==i){
spCodesTemp = $(this)val();
}else{
spCodesTemp += (","+$(this)val());
}
});
$("#txt_spCodes")val(spCodesTemp);
以上就是关于怎样获取input为checkbox选中的值全部的内容,包括:怎样获取input为checkbox选中的值、C#中获取CheckBox选中的值(多选)、jQuery获取checkbox选中行的所有值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)