jquery获取div中checkbox 选中的个数

jquery获取div中checkbox 选中的个数,第1张

1.HTML结构

< input type = "checkbox" name = "test" value = "1" / > < span > 1 < / span >

< input type = "checkbox" name = "test" value = "2" / > < span > 2 < / span >

< input type = "checkbox" name = "test" value = "3" / > < span > 3 < / span >

< input type = "checkbox" name = "test" value = "4" / > < span > 4 < / span >

< input type = "checkbox" name = "test" value = "5" / > < span > 5 < / span >

2.Javascript代码:

函数show(){

Obj文件。getElementsByName(“测试”);

Check_val=[];

For(kinobj){

如果(obj[k]。检查)

Check_val。Push(obj[k]。值);

警报(check_val);

扩展资料:

JQuery对复选框的各种 *** 作:

1.根据id获取复选框:

$("#cbCheckbox1");

2.得到所有的复选框:

$("input[type='checkbox']");//或

$("input[name='cb']");

3.获得所有选中的复选框:

$("input:thecheckboxchecked");//或

$("input:[type='checkbox']:checked");//或

$("input[type='checkbox]:checked");//或

$("input:[name='ck']:checked");

这是拼table的代码

for ( var i = 0; i < totalCount; i++) {

var prodHtml = "";

prodHtml +="<tr>";

prodHtml +=" <td class='center'><label><input type='checkbox' class='ace' /><span class='lbl'></span></label></td>";

prodHtml +=" <td>"+responsedatacycleMaps[i]prodCode+"</td>";

prodHtml +=" <td>"+responsedatacycleMaps[i]prodName+"</td>";

prodHtml +=" <td>"+responsedatacycleMaps[i]price+"</td>";

prodHtml +=" <td>"+responsedatacycleMaps[i]prodType+"</td>";

prodHtml +=" <td>"+responsedatacycleMaps[i]backFlag+"</td>";

prodHtml +=" <td>"+responsedatacycleMaps[i]custodyFlag+"</td>";

prodHtml +=" <td></td>";

prodHtml += "</tr>";

$('#selectedProds')append(prodHtml);

}

这是点击下一步按钮时候的方法:

function xiayibu(){

需要获取到上面table中checkbox选中的行的值,并再使用上面的方法在另一个页面中重新显示一遍

}

获取一组radio被选中项的值

var item = $('input[@name=items][@checked]')val();

获取select被选中项的文本

var item = $("select[@name=items] option[@selected]")text();

select下拉框的第二个元素为当前选中值

$('#select_id')[0]selectedIndex = 1;

radio单选组的第二个元素为当前选中值

$('input[@name=items]')get(1)checked = true; 获取值: 文本框,文本区域:$("#txt")attr("value");

多选框checkbox:$("#checkbox_id")attr("value");

单选组radio: $("input[@type=radio][@checked]")val();

下拉框select: $('#sel')val(); 控制表单元素:

文本框,文本区域:$("#txt")attr("value",'');//清空内容

$("#txt")attr("value",'11');//填充内容 多选框checkbox: $("#chk1")attr("checked",'');//不打勾

$("#chk2")attr("checked",true);//打勾

if($("#chk1")attr('checked')==undefined) //判断是否已经打勾 单选组radio: $("input[@type=radio]")attr("checked",'2');//设置value=2的项目为当前选中项 (错)

$("input[@name=radio_s][@value=16]")attr("checked",true);(测试通过)下拉框select: $("#sel")attr("value",'-sel3');//设置value=-sel3的项目为当前选中项

$("<option value='1'>1111</option><option value='2'>2222</option>")appendTo("#sel")//添加下拉框的option

$("#sel")empty();//清空下拉框$("#select1")[0]options(index)selected = true; //使第index个option选中

$("#select1")[0]options(3)text //取索引为3的option值

<input type=checkbox id="member_id" name="member_id" value="${oneid}">

代码不有点问题

<input type="checkbox" id="member_id" name="member_id" value="${oneid}">

基本的格式符号都省略了

思路:通过 :checked 筛选 checkbox 选中项,然后进行遍历,利用节点关系获取到input对象,最后使用val()方法获取input的内容。实例演示如下:

1、HTML结构

<table>

    <tr>

        <td><input type="checkbox" name="test"></td>

        <td><input type="text"></td><td><input type="text"></td>

    </tr>

    <tr>

        <td><input type="checkbox" name="test"></td>

        <td><input type="text"></td><td><input type="text"></td>

    </tr>

</table>

<input type="button" value="确定">

2、jquery代码

$(function(){

    $(":button")click(function() {

// 找到选中行的input

var ipts = $(":checkbox:checked")parents("tr")find("input:text");  

// 遍历input并使用val()方法获取值

        str = map(function() {return $(this)val();})get()join(", ");

        alert(str);

    });

});

3、效果演示

以上就是关于jquery获取div中checkbox 选中的个数全部的内容,包括:jquery获取div中checkbox 选中的个数、jquery 如何获取table里面的checkbox、Jquery如何获取设置radio select checkbox 文本框等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9449980.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-28
下一篇2023-04-28

发表评论

登录后才能评论

评论列表(0条)

    保存