使用复选框名称获取复选框值 [英] Get checkbox values using checkbox name

查看:127
本文介绍了使用复选框名称获取复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所以,我需要得到这个复选框的每个值,并且我希望使用这个值作为输入复选框(它们的名称与服务器上的发送数组的名称相同)。

 < form>选择器复选框名称,这不起作用,请帮助。 
< input type =checkboxname =bla []value =1/>
< input type =checkboxname =bla []value =2/>
< / form>

js:

 < code $ $(document).ready(function(){

$(input [name = bla])。each(function(){
alert($ this).val());
});

});

DEMO

解决方案

您正在选择名称属性为bla code>,但是你的输入具有bla []名称属性。

  $(input [name ='bla []'])。each(function(){

http://jsfiddle.net/26axX/


I have several input checkboxes, (they name is same for send array on server).

So, I need get each value this checkboxes and I want use as selector checkbox names, this not works, help please.

<form>
  <input type="checkbox" name="bla[]" value="1" />
  <input type="checkbox" name="bla[]" value="2" />
</form>

js:

$(document).ready( function () {    

   $("input[name=bla]").each( function () {
       alert( $(this).val() );
   });

});

DEMO

解决方案

You are selecting inputs with name attribute of "bla", but your inputs have "bla[]" name attribute.

$("input[name='bla[]']").each( function () {

http://jsfiddle.net/26axX/

这篇关于使用复选框名称获取复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆