Jquery checkbox 选择问题.

霜寒月冷 2016-04-30 08:27:08
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<span class='yuan'>数学:3000<input name='kemu' class="jscheck" type='checkbox' title="no2" value="111" /></span>
<span class='yuan'>语文:1000<input name='kemu' class="jscheck" type='checkbox' title="no1" value="22" /></span>
<span class='yuan'>英语:500<input name='kemu' class="jscheck" type='checkbox' title="no3" value="33" /></span>
<input type="button" id="test" />

</body>
</html>

<script type="text/javascript">
$(document).ready(function () {

});
$("#test").click(function () {
var array = '';
$('input[name="kemu"]:checked').each(function () {
array = array + $(this).val()+",";
});
alert(array);
});

</script>


如上 代码只能取出 checkbox 里面的 value 值
并不能取得 span 中的文本值,现想是 遍历中 span 中的checkbox 被选择 则显示 span 中 text 的值。
如果第一、二 个checkbox 被选择 我需要的结果是:数学:3000,语文:1000

...全文
164 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2016-04-30
  • 打赏
  • 举报
回复
$(this).parent().attr("cid")
霜寒月冷 2016-04-30
  • 打赏
  • 举报
回复
<span class='yuan' cid="c1">数学:3000<input name='kemu1' class="jscheck" type='checkbox' title="no2" value="111" /></span> <span class='yuan' cid="c2">语文:1000<input name='kemu2' class="jscheck" type='checkbox' title="no1" value="22" /></span> <span class='yuan' cid="c3">英语:500<input name='kemu3' class="jscheck" type='checkbox' title="no3" value="33" /></span> 如果要获得这个cid 里面的值,可以实现么?
霜寒月冷 2016-04-30
  • 打赏
  • 举报
回复
引用 1 楼 net_lover 的回复:
array = array + $(this).parent().text()+","; 就可以了
上述可以实现,还想问下
孟子E章 2016-04-30
  • 打赏
  • 举报
回复
array = array + $(this).parent().text()+","; 就可以了

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧