免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2238 | 回复: 1
打印 上一主题 下一主题

jquery获取radio,select,checkbox的值-精简版 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-01-11 11:09 |只看该作者 |倒序浏览
jquery获取radio,select,checkbox的值-精简版







// 循环获取radio的值
Js代码
  1. var level_important = 0;   
  2.     var list = $("input[type='radio'][name='" + ("radio_level_important_" + id)   
  3.             + "']");   
  4.     list.each(function() {   
  5.                 if ($(this).attr('checked') == "checked") {   
  6.                     level_important = $(this).val();   
  7.                 }   
  8.             });   
  9.     level_important = level_important == 0 ? 2 : level_important;  

  10. var level_important = 0;
  11.         var list = $("input[type='radio'][name='" + ("radio_level_important_" + id)
  12.                         + "']");
  13.         list.each(function() {
  14.                                 if ($(this).attr('checked') == "checked") {
  15.                                         level_important = $(this).val();
  16.                                 }
  17.                         });
  18.         level_important = level_important == 0 ? 2 : level_important;
复制代码
循环获取checkbox的值
Js代码
  1. // 删除按钮单击事件   
  2.     $("#delete").click(function() {   
  3.         var ids = "";   
  4.         var list = $("input[type='checkbox'][name='ids']");   
  5.         list.each(function() {   
  6.                     if ($(this).attr('checked') == "checked") {   
  7.                         ids += $(this).val() + ",";   
  8.                     }   
  9.                 });   
  10.         if ($.trim(ids)) {   
  11.             ids = ids.substring(0, ids.length - 1);   
  12.             if (confirm("确定要删除所选择的项次吗?")) {   
  13.                 location.href = "department!deleteBatch.action?department.code="  
  14.                         + ids;   
  15.             }   
  16.         } else {   
  17.             alert("请选择所要操作的项次!");   
  18.         }   
  19.     });  

  20. // 删除按钮单击事件
  21.         $("#delete").click(function() {
  22.                 var ids = "";
  23.                 var list = $("input[type='checkbox'][name='ids']");
  24.                 list.each(function() {
  25.                                         if ($(this).attr('checked') == "checked") {
  26.                                                 ids += $(this).val() + ",";
  27.                                         }
  28.                                 });
  29.                 if ($.trim(ids)) {
  30.                         ids = ids.substring(0, ids.length - 1);
  31.                         if (confirm("确定要删除所选择的项次吗?")) {
  32.                                 location.href = "department!deleteBatch.action?department.code="
  33.                                                 + ids;
  34.                         }
  35.                 } else {
  36.                         alert("请选择所要操作的项次!");
  37.                 }
  38.         });
复制代码
判断checkbox是否选中
Js代码
  1. var report_status = $("#chk_report_status_" + id).attr('checked')   
  2.             ? "Y"  
  3.             : "N";  

  4. var report_status = $("#chk_report_status_" + id).attr('checked')
  5.                         ? "Y"
  6.                         : "N";
复制代码
获取select的值
Js代码
  1. var categories_belong = $("#categories_belong_" + id).val();   
  2.   
  3. or   
  4.   
  5. var categories_belong = $("#categories_belong_" + id).text();  
复制代码

论坛徽章:
0
2 [报告]
发表于 2012-01-12 10:35 |只看该作者
谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP