• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
罗小亭
博客园    首页    新随笔    联系   管理    订阅  订阅
获取checkbox后面的文本内容

http://alygle.blog.51cto.com/1922399/669040

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
<title>获取checkbox后的文本</title> 
</head> 
<script language="javascript"> 
function getChkValue(){  
    var obj=document.getElementsByName("intrests");  
    for(var i=0;i<obj.length;i++){  
         if(obj[i].checked){  
         alert(obj[i].value+","+obj[i].nextSibling.nodeValue);  
       }  
    }       
}  
</script> 
<body> 
   <form name="form1" method="post" action=""> 
      <input type="checkbox" name="intrests" value="1">a<br> 
      <input type="checkbox" name="intrests" value="2">b<br> 
      <input type="checkbox" name="intrests" value="3">c<br> 
      <input type="checkbox" name="intrests" value="4">d<br> 
      <input type="checkbox" name="intrests" value="5">e<br> 
      <input type="checkbox" name="intrests" value="6">f<br> 
      <input type="checkbox" name="intrests" value="7">g<br> 
      <input type="checkbox" name="intrests" value="8">h<br><br> 
      <input type="button" onclick="getChkValue()" value="提交"> 
   </form> 
</body> 
</html> 

 

posted on 2016-01-12 14:13  罗小亭  阅读(1919)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3