Html 单个页面上有多个复选框

Html 单个页面上有多个复选框,html,css,input,checkbox,tilde,Html,Css,Input,Checkbox,Tilde,有人能帮我解决我的评分系统吗?我试图用容器类(整个progressbar)复制我的节,但每当我这样做时,ratingbar只对其中一个progressbar有效。我一直在考虑更改第二个复选框的id,以便它们不会干扰。这是带有一个进度条的代码,但我想要更多 顺便说一句,如果有人知道一个体面的方式来分享我这里混乱的代码,这将是有益的 PHP+HTML: <?php $num = 2; ?> <!DOCTYPE html> <html lang="en"> <

有人能帮我解决我的评分系统吗?我试图用容器类(整个progressbar)复制我的节,但每当我这样做时,ratingbar只对其中一个progressbar有效。我一直在考虑更改第二个复选框的id,以便它们不会干扰。这是带有一个进度条的代码,但我想要更多

顺便说一句,如果有人知道一个体面的方式来分享我这里混乱的代码,这将是有益的

PHP+HTML:

<?php $num = 2; ?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Animated Progress Bar</title>
  <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <section class="container">
        <input type="radio" class="radio twenty" name="progress" value="twenty" id="twenty" <?php if($num === 1) { echo 'checked'; } ?>>
        <label for="twenty" class="label">1</label>

        <input type="radio" class="radio fourty" name="progress" value="fourty" id="fourty" <?php if($num === 2) { echo 'checked'; } ?>>
        <label for="fourty" class="label">2</label>

        <input type="radio" class="radio sixty" name="progress" value="sixty" id="sixty" <?php if($num === 3) { echo 'checked'; } ?>>
        <label for="sixty" class="label">3</label>

        <input type="radio" class="radio eighty" name="progress" value="eighty" id="eighty"<?php if($num === 4) { echo 'checked'; } ?>>
        <label for="eighty" class="label">4</label>

        <input type="radio" class="radio onehundred" name="progress" value="onehundred" id="onehundred" <?php if($num === 5) { echo 'checked'; } ?>>
        <label for="onehundred" class="label">5</label>

        <div class="progress">
            <div class="progress-bar"></div>
        </div>
    </section>
</body>
</html>
请尝试以下代码:

PHP+HTML

 <?php
     $num = 3;
 ?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Animated Progress Bar</title>
  <link rel="stylesheet" href="my.css">
</head>
<body>
    <section class="container">
        <input type="radio" class="radio twenty" name="progress" value="twenty" id="twenty" <?php if($num === 1) { echo 'checked'; } ?>>
        <label for="twenty" class="label">1</label>

        <input type="radio" class="radio fourty" name="progress" value="fourty" id="fourty" <?php if($num === 2) { echo 'checked'; } ?>>
        <label for="fourty" class="label">2</label>

        <input type="radio" class="radio sixty" name="progress" value="sixty" id="sixty" <?php if($num === 3) { echo 'checked'; } ?>>
        <label for="sixty" class="label">3</label>

        <input type="radio" class="radio eighty" name="progress" value="eighty" id="eighty"<?php if($num === 4) { echo 'checked'; } ?>>
        <label for="eighty" class="label">4</label>

        <input type="radio" class="radio onehundred" name="progress" value="onehundred" id="onehundred" <?php if($num === 5) { echo 'checked'; } ?>>
        <label for="onehundred" class="label">5</label>

        <div class="progress">
            <div class="progress-bar"></div>
        </div>
    </section>

    <section class="container">
        <input type="radio" class="radio twenty2" name="progress2" value="twenty" id="twenty2" <?php if($num === 1) { echo 'checked'; } ?>>
        <label for="twenty2" class="label">1</label>

        <input type="radio" class="radio fourty2" name="progress2" value="fourty" id="fourty2" <?php if($num === 2) { echo 'checked'; } ?>>
        <label for="fourty2" class="label">2</label>

        <input type="radio" class="radio sixty2" name="progress2" value="sixty" id="sixty2" <?php if($num === 3) { echo 'checked'; } ?>>
        <label for="sixty2" class="label">3</label>

        <input type="radio" class="radio eighty2" name="progress2" value="eighty" id="eighty2"<?php if($num === 4) { echo 'checked'; } ?>>
        <label for="eighty2" class="label">4</label>

        <input type="radio" class="radio onehundred2" name="progress2" value="onehundred" id="onehundred2" <?php if($num === 5) { echo 'checked'; } ?>>
        <label for="onehundred2" class="label">5</label>

        <div class="progress2">
            <div class="progress-bar"></div>
        </div>
    </section>
</body>
</html>
这对我来说非常有用,您只需要修改下一个进度条的下一个名称、类和css

在本例中,我尝试在下一个进度条中添加
progress2、twenty2

好吧,如果你想在一个页面中创建这么多进度条,你可能想在php中循环html,或者你可以使用jQuery来操作DOM


希望这能奏效

对于第二个进度组,您需要更改以下内容

  • 每个输入元素的
    id
    (不选收音机复选框)
  • 标签的
    for
    属性与输入元素的新
    id
    相对应
  • 输入元素的
    名称
    ,因为它们是按名称分组的单选按钮
因此,第二组将生成此html结构

<section class="container">
    <input type="radio" class="radio twenty" name="progress-2" value="twenty" id="twenty-2" />
    <label for="twenty-2" class="label">1</label>
    <input type="radio" class="radio fourty" name="progress-2" value="fourty" id="fourty-2" />
    <label for="fourty-2" class="label">2</label>
    <input type="radio" class="radio sixty" name="progress-2" value="sixty" id="sixty-2" />
    <label for="sixty-2" class="label">3</label>
    <input type="radio" class="radio eighty" name="progress-2" value="eighty" id="eighty-2" />
    <label for="eighty-2" class="label">4</label>
    <input type="radio" class="radio onehundred" name="progress-2" value="onehundred" id="onehundred-2" />
    <label for="onehundred-2" class="label">5</label>
    <div class="progress">
        <div class="progress-bar"></div>
    </div>
</section>

1.
2.
3.
4.
5.

工作演示谢谢,我不太喜欢单选按钮,所以我忘记了编辑第二组的名称并将它们全部分组。Doh。非常感谢您阅读了这一系列代码!忘了自己更改第二组的名称。非常感谢您阅读代码并帮助我解决问题!
body {
  font: 13px/20px 'Lucida Grande', Tahoma, Verdana, sans-serif;
  color: #404040;
  background: #323232;
}
.container {
  margin: 80px auto;
  width: 640px;
  text-align: center;
}
.container .progress, .container .progress2 {
  margin: 0 auto;
  width: 150px;
}
.progress, .progress2 {
  padding: 4px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08);
}
.progress-bar {
  position: relative;
  height: 10px;
  border-radius: 4px;
  -webkit-transition: 0.4s linear;
  -moz-transition: 0.4s linear;
  -o-transition: 0.4s linear;
  transition: 0.4s linear;
  -webkit-transition-property: width, background-color;
  -moz-transition-property: width, background-color;
  -o-transition-property: width, background-color;
  transition-property: width, background-color;
  -webkit-box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.25), inset 0 1px rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.25), inset 0 1px rgba(255, 255, 255, 0.1);
}
.progress-bar:before, .progress-bar:after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}
.progress-bar:before {
  bottom: 0;
  border-radius: 4px 4px 0 0;
}
.progress-bar:after {
  z-index: 2;
  bottom: 45%;
  border-radius: 4px;
  background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
  background-image: -moz-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
  background-image: -o-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
  background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05));
}
.twenty:checked ~ .progress > .progress-bar, .twenty2:checked ~ .progress2 > .progress-bar {
  width: 20%;
  background-color: #f63a0f;
}
.fourty:checked ~ .progress > .progress-bar, .fourty2:checked ~ .progress2 > .progress-bar {
  width: 40%;
  background-color: #f27011;
}
.sixty:checked ~ .progress > .progress-bar, .sixty2:checked ~ .progress2 > .progress-bar {
  width: 60%;
  background-color: #f2b01e;
}
.eighty:checked ~ .progress > .progress-bar, .eighty2:checked ~ .progress2 > .progress-bar {
  width: 80%;
  background-color: #f2d31b;
}
.onehundred:checked ~ .progress > .progress-bar, .onehundred2:checked ~ .progress2 > .progress-bar {
  width: 100%;
  background-color: #86e01e;
}
.radio {
  display: none;
}
.label {
  display: inline-block;
  margin: 0 5px 20px;
  padding: 3px 8px;
  color: #aaa;
  text-shadow: 0 1px black;
  border-radius: 3px;
  cursor: pointer;
}
.radio:checked + .label {
  color: white;
  background: rgba(0, 0, 0, 0.25);
}
<section class="container">
    <input type="radio" class="radio twenty" name="progress-2" value="twenty" id="twenty-2" />
    <label for="twenty-2" class="label">1</label>
    <input type="radio" class="radio fourty" name="progress-2" value="fourty" id="fourty-2" />
    <label for="fourty-2" class="label">2</label>
    <input type="radio" class="radio sixty" name="progress-2" value="sixty" id="sixty-2" />
    <label for="sixty-2" class="label">3</label>
    <input type="radio" class="radio eighty" name="progress-2" value="eighty" id="eighty-2" />
    <label for="eighty-2" class="label">4</label>
    <input type="radio" class="radio onehundred" name="progress-2" value="onehundred" id="onehundred-2" />
    <label for="onehundred-2" class="label">5</label>
    <div class="progress">
        <div class="progress-bar"></div>
    </div>
</section>