0

我有一个包含多个复选框的表单,我想像这样将复选框的值插入到 url

var a=encodeURIComponent(document.getElementById("idofcheckbox").value)
xmlhttp.open("GET","InsertPHPData.php?q="+a+,true); xmlhttp.send();
choix1
choix2
4

1 回答 1

2

尝试这个:

var x = document.getElementsByTagName("input");

var params = [];
for (var i = 0; i < x.length; i++) {
    if (x[i].type === "checkbox") //&& x[i].checked === true 
        params.push(x[i].name + "+" + x[i].value);
}

var url = "InsertPHPData.php";
url += "?" + encodeURI(params.join(","));

alert(url)​

工作小提琴。请相应修改:)

于 2012-11-03T17:28:50.167 回答