首页 > 编程知识 正文

js动态添加checkbox标签,js的checkbox

时间:2023-12-27 22:26:53 阅读:325133 作者:GQWD

本文目录一览:

ajax怎么获取js动态添加的标签的值

你要获取的是选中的checkbox值是吧?那你这样写,名为头图的给一个name,别的都给一个name.

这样写:

input name="checkbox1" type="checkbox" value="头图" /头图

input name="checkbox1" type="checkbox" value="头图" /头图

input name="checkbox1" type="checkbox" value="头图" /头图

剩下的几个同理。

想取得值,这样写:

var checkbox1 = document.getElementsByName("checkbox1");

var checkboxAll1="";

for(var i=0;icheckbox1.length;i++){

if(checkbox1[i].checked){

checkboxAll1+=checkbox1[i].value+","//将选中的值拼接,用“,”隔开

}

}

这里checkboxAll1就是你头图的所有选中的值,你把这个值传到action中处理,只要获得这个值,然后checkboxAll1.split(",");得到一个数组,数组元素就是你要的结果,然后遍历数组就可以了。

如果你每一个都有id,可以用js:

document.getElementById(这里是id值).value;

或者:$("#后边是id").val();就可以取到,但是这样不能判断你获取的值已经选中。你还需要挨个判断,所以,用我上边的方法,用for循环判断可以提高效率。希望对你有帮助。

如何用js动态生成checkboxList

td colspan="3" class="clearWidth" style="text-align:left;"span id="ctl00_cphDisplay_cblstPosition" onclick="checkSelectCount(this);"input id="ctl00_cphDisplay_cblstPosition_0" type="checkbox" name="ctl00$cphDisplay$cblstPosition$0"label for="ctl00_cphDisplay_cblstPosition_0"机动车道/labelinput id="ctl00_cphDisplay_cblstPosition_1" type="checkbox" name="ctl00$cphDisplay$cblstPosition$1"label for="ctl00_cphDisplay_cblstPosition_1"步行道/labelinput id="ctl00_cphDisplay_cblstPosition_2" type="checkbox" name="ctl00$cphDisplay$cblstPosition$2"label for="ctl00_cphDisplay_cblstPosition_2"非机动车道/labelinput id="ctl00_cphDisplay_cblstPosition_3" type="checkbox" name="ctl00$cphDisplay$cblstPosition$3"label for="ctl00_cphDisplay_cblstPosition_3"盲道/labelinput id="ctl00_cphDisplay_cblstPosition_4" type="checkbox" name="ctl00$cphDisplay$cblstPosition$4"label for="ctl00_cphDisplay_cblstPosition_4"混行道/labelinput id="ctl00_cphDisplay_cblstPosition_5" type="checkbox" name="ctl00$cphDisplay$cblstPosition$5"label for="ctl00_cphDisplay_cblstPosition_5"其它/label/span/td

js 这里的复选框是怎么加上去的?

这个是浏览器的功能,并不是你可以通过代码控制的.在IE下你就看不到这个复选框

用Javascript动态创建CheckBox

比如在某个div id="a"/div

里面添加一个checkBox

document.getElementById("a").innerHTML = "input type='checkbox' checked /";

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。