-2

我很高兴你能帮助我。当复选框被选中时,我想使用 css、html 和 javascript 在 p 标签内绘制文本。

4

2 回答 2

0

这是一个显示复选框的选中和未选中状态的工作示例:

<!DOCTYPE html>
<html>
    <head>
        <title>Checkbox demo</title>
    </head>
    <body>
        <span>Checkbox:</span> 
        <input type="checkbox" id="my-checkbox" onclick="myFunction()">
        <p id="result">Page loaded</p>
        <script>
          function myFunction() {
            var checkBox = document.getElementById("my-checkbox");
            var result = document.getElementById("result");
            if (checkBox.checked == true){
              result.innerHTML = "Checkbox was checked"
            } else {
              result.innerHTML = "Checkbox was un-checked"
            }
          }
        </script>
  </body>
</html>

输出:

在此处输入图像描述

更多信息:

https://www.w3schools.com/howto/howto_js_display_checkbox_text.asp

于 2020-05-31T18:24:24.393 回答
0

尝试这个:

<!DOCTYPE html>
<html>
<head>
<style> 
input:checked {
  height: 50px;
  width: 50px;
}
</style>
</head>
<body>

<form action="">
  <input type="radio" checked="checked" value="male" name="gender"> Male<br>
  <input type="radio" value="female" name="gender"> Female<br>
  <input type="checkbox" checked="checked" value="Bike"> I have a bike<br>
  <input type="checkbox" value="Car"> I have a car 
</form>

</body>
</html>

于 2020-05-31T18:25:41.117 回答