<td><input id= name="knowFrom" type="checkbox" value="" /> TV</td>如何取出这个checkbox后面跟的文本?
解决方案 »
- jquery想要查找data='number'这样parent.find("a[data='number']")为什么不行
- returnValue问题,请求帮忙
- 怎么防止倒计时刷新就返回原时间!
- 一个需求不是很理解,大家给个思路或给个参考
- 如何在编辑区域中显示上传文件的完整路径?
- 求助,有关checkbox的,,,ckecked属性。,。。
- 请教高手,我现在想根据从数据库中取得值。来调整一些<td>的顺序,怎么实现呢!!散分啦!!
- 如何不让别人看到我在jsp中引用的js文件
- 求js算法,对ids列进行排序,并且保证names列的值对应关系不变
- DOJO的xhrGET发出请求,返回时整个页面
- 小说排版问题
- javascript中如何实现字符串分段赋值
真有才
取标签的Text
$("#knowFrom").next().text()
// if (2>1) return "";
var value = "";
$(":input[name='"+name+"']").filter("[checked=true]").each(function() {
var $obj=this;
if (this.checked) {
if (value == "") value += $obj.siblings().text();
else value += "-" + $obj.siblings().text();
}
}); return value;
}用3楼的办法,在控制台中报错说siblings()不是函数.不能改html,因为定义了很多样式,修改成label的css可能失效,css是美工做的.
OR
$("#knowFrom").parent().text()
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Untitled Document</title>
<script language="JavaScript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
$("#_but").click(function(){
$("input[name='knowFrom'][checked]").each(function(){
alert($(this).parent().text());
});
});
});
</script>
</head>
<body>
<table>
<tr>
<td><input name="knowFrom" type="checkbox" value="1" />TV11</td>
</tr>
<tr>
<td><input name="knowFrom" type="checkbox" value="2" />TV2</td>
</tr>
<tr>
<td><input name="knowFrom" type="checkbox" value="3" />TV321</td>
</tr>
<tr>
<td><input name="knowFrom" type="checkbox" value="4" />TV4000</td>
</tr>
</table>
<input type="button" name="but" id="_but" value="取text">
</body>
</html>
$("input[type='checkbox']).each(function(i){
$(this).innerHTML
})
text()返回满足条件的所有文本,应该不用再写函数了吧
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Untitled Document</title>
<script language="JavaScript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function(){
$("#_but").click(function(){
var checks = $("input[name='knowFrom']:checked");
$.each(checks,function(idx,obj){
alert($(obj).parent("td").text());
})
});
});
</script>
</head>
<body>
<table>
<tr>
<td><input name="knowFrom" type="checkbox" value="1" />TV11</td>
</tr>
<tr>
<td><input name="knowFrom" type="checkbox" value="2" />TV2</td>
</tr>
<tr>
<td><input name="knowFrom" type="checkbox" value="3" />TV321</td>
</tr>
<tr>
<td><input name="knowFrom" type="checkbox" value="4" />TV4000</td>
</tr>
</table>
<input type="button" name="but" id="_but" value="取text">
</body>
</html>
这个效果么?
$(function(){
$("#_but").click(function(){
var checks = $("input[name='knowFrom']:checked");
$.each(checks,function(){
alert($(this).parent().text());
})
});
});
</script>