Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.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
如何在javascript中获取复选框值_Javascript_Html_Checkbox_Html Input - Fatal编程技术网

如何在javascript中获取复选框值

如何在javascript中获取复选框值,javascript,html,checkbox,html-input,Javascript,Html,Checkbox,Html Input,我的HTML脚本是 <html> <body> <b><font color="green">Please select a check box to change the color of text </font> </b><br> <input type="checkbox" name="red" id="chkbx" > &nbsp; Red<br>

我的HTML脚本是

<html>

    <body>
    <b><font color="green">Please select a check box to change the color of text </font> </b><br>
    <input type="checkbox" name="red"  id="chkbx" > &nbsp; Red<br>
    <input type="checkbox" name="green" id="chkbx" value="1"> &nbsp; Green <br>
    <input type="checkbox" name="blue" id="chkbx" value="2"> &nbsp; Blue <br>
    <input type="checkbox" name="orange" id="chkbx" value="3"> &nbsp; Orange <br>
    <input type="checkbox" name="yellow" id="chkbx" value="4"> &nbsp; Yellow <br>
    <p id="demo"></p>

    <button onclick="myfunction()">My Choice</button>
<br><br>
    <h style="color: red; font-weight: bold;"> </h>
    <p id="demo"></p>

请选中复选框以更改文本的颜色
红色
绿色
蓝色
橙色
黄色

我的选择


我需要获取javascript中的复选框值,如果选中任何一个复选框,该颜色将应用于文本以显示在输出上。如何做?

首先-不要使用该标记,因为它自1999年使用以来就被弃用了

<p style='font-weight:bold; color:green'>....</p>