Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选中(或不选中)复选框的URL连接javascript_Javascript_Html_Ajax_Url_Get - Fatal编程技术网

选中(或不选中)复选框的URL连接javascript

选中(或不选中)复选框的URL连接javascript,javascript,html,ajax,url,get,Javascript,Html,Ajax,Url,Get,我有一个“发送人”的代码,关于复选框是否被选中,该代码为true或false: var isChecked = document.myform.checkbox.checked ? 1 : 0; var isChecked0 = document.myform.checkbox0.checked ? 1 : 0; var isChecked1 = document.myform.checkbox1.checked ? 1 : 0; xmlhttp.open("GET","roulette2.p

我有一个“发送人”的代码,关于复选框是否被选中,该代码为true或false:

var isChecked = document.myform.checkbox.checked ? 1 : 0;
var isChecked0 = document.myform.checkbox0.checked ? 1 : 0;
var isChecked1 = document.myform.checkbox1.checked ? 1 : 0;

xmlhttp.open("GET","roulette2.php?boxchecked=" + isChecked,true);
xmlhttp.send();
html如下所示:

<input type="checkbox" name="checkbox" value="checkbox" />00<br />
<input type="checkbox" name="checkbox0" value="checkbox" />0<br />
<input type="checkbox" name="checkbox1" value="checkbox" />1<br />
这仅验证是否单击了第一个复选框,而不是其他复选框

如何修改
xmlhttp.open
以激活3个复选框“要选中的选项”

提前谢谢


Trufa

是否要在一个变量中发送所有已检查状态

在字符串中连接状态:

var dm = document.myform;
var isCheched = (dm.checkbox.checked ? "1" : "0")+
(dm.checkbox0.checked ? "1" : "0") +
(dm.checkbox1.checked ? "1" : "0");
如果未选中任何复选框,则得到000;如果选中复选框,则得到001;如果选中全部复选框,则得到111

更新

我又看了一遍你的代码,看到了轮盘赌。。。你在写轮盘赌游戏吗?那么这可能有用:

function submitRoulette( ) {
    var i,box;
    var boxes = document.getElementById("roulette").getElementsByTagName("input");
    var checked=[]; // We are going to conatenate the values in this array.

    for (i=0; i < boxes.length; ++i) {
        box = boxes[i];
        if (box.name=="b" && box.checked) {
            checked.push(box.value);
        }
    }

    checked = checked.join(""); // Converts the array to a string.

    xmlhttp.open("GET","roulette2.php?boxchecked=" + checked,true);
    xmlhttp.send();

    return false; // Prevents the form from being submited the normal way
}

是的,这很重要,它们中的任何一个都可以单独或以任何组合进行检查possible@Trufa:没问题,很乐意帮忙。我希望更新会对你有更大的帮助:)@有些你不该打扰的!!非常感谢,我来看看!我正在用一个MySQL数据库编写一个php轮盘游戏,所以你可以想象它不是很互动,也不是很有趣:)用一点AJAX来提高赌注!再次感谢你真的太好了@特鲁法:没问题!如果我从一开始就知道你有3个以上的复选框,我会给出一个循环的例子。通过设置不同的复选框值,发送到php脚本的字符串尽可能短;不需要发送未选中复选框的状态。祝你好运和快乐!顺便说一句,因为每个复选框都有自己的唯一值,所以复选框的顺序并不重要。把它们放在你想放的地方。@gret,我用三个放在第一位,因为我不太“信任”我的代码,所以如果我必须测试17个出现时是否回显“你赢了”,要从36中猜出幸运数字真的很无聊:)我知道可能有聪明的方法来测试这一点,但这是我下一个问题的主题。再次感谢你,你真的帮了我很大的忙!
function submitRoulette( ) {
    var i,box;
    var boxes = document.getElementById("roulette").getElementsByTagName("input");
    var checked=[]; // We are going to conatenate the values in this array.

    for (i=0; i < boxes.length; ++i) {
        box = boxes[i];
        if (box.name=="b" && box.checked) {
            checked.push(box.value);
        }
    }

    checked = checked.join(""); // Converts the array to a string.

    xmlhttp.open("GET","roulette2.php?boxchecked=" + checked,true);
    xmlhttp.send();

    return false; // Prevents the form from being submited the normal way
}
<form id="roulette" method="post" action="" onsubmit="return submitRoulette()">
<div>
    <span><input type="checkbox" name="b" value="0" />0</span>
    <span><input type="checkbox" name="b" value="-" />zero</span>
    <span><input type="checkbox" name="b" value="z" />00</span>
</div>

<div>
    <span><input type="checkbox" name="b" value="1" />1</span>
    <span><input type="checkbox" name="b" value="2" />2</span>
    <span><input type="checkbox" name="b" value="3" />3</span>
    <span><input type="checkbox" name="b" value="b" />1-3</span>
</div>
[snip]
<div>
    <span><input type="checkbox" name="b" value="V" />31</span>
    <span><input type="checkbox" name="b" value="W" />32</span>
    <span><input type="checkbox" name="b" value="X" />33</span>
    <span><input type="checkbox" name="b" value="l" />31-33</span>
</div>
<div>
    <span><input type="checkbox" name="b" value="Y" />34</span>
    <span><input type="checkbox" name="b" value="Z" />35</span>
    <span><input type="checkbox" name="b" value="a" />36</span>
    <span><input type="checkbox" name="b" value="m" />34-36</span>
</div>
<div>
    <span><input type="checkbox" name="b" value="n" />1..34</span>
    <span><input type="checkbox" name="b" value="o" />2..35</span>
    <span><input type="checkbox" name="b" value="p" />3..36</span>
</div>

<div>
    <span><input type="checkbox" name="b" value="q" />1-12</span>
    <span><input type="checkbox" name="b" value="r" />13-24</span>
    <span><input type="checkbox" name="b" value="s" />25-36</span>
</div>
<div>
    <span><input type="checkbox" name="b" value="t" />1-18</span>
    <span><input type="checkbox" name="b" value="u" />19-36</span>
</div>
<div>
    <span><input type="checkbox" name="b" value="v" />odd</span>
    <span><input type="checkbox" name="b" value="w" />even</span>
    <span><input type="checkbox" name="b" value="x" />red</span>
    <span><input type="checkbox" name="b" value="y" />black</span>
</div>

<button type="submit">Send</button>
</form>
0-35 is 0-9,A-Z and 36 = a.
row 1 (1-3) = b, row 2 (4-6) = c ... row 12 (33-36) = m
col 1 (1..34) = n, col 2(2-24) = o, col 3(3-36) = p
1-12 = q, 13-24 = r, 25-36 = s
1-18 = t, 19-36 = u
odd = v, even = w
red = x, black = y
00 = x
0 or 00 = - (minus)