选中复选框时动态更改引导程序进度条值

2023-12-29

我正在尝试制作一个带有引导进度条的动态清单。这是我的标记代码

<div class="progress progress-striped active">
    <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
    </div>
</div>
<div class="row tasks">
    <div class="col-md-6">
        <p><span><?php echo $title; ?></span><?php echo $description; ?></p>
    </div>
    <div class="col-md-2">
        <label><?php echo $date; ?></label>
    </div>
    <div class="col-md-2">
        <input type="checkbox" name="progress" class="progress" value="<?php echo $progress; ?>">
    </div>
    <div class="col-md-2">
        <input type="checkbox" name="done" class="done" value="<?php echo $done; ?>">
    </div>
</div><!-- tasks -->

我想要做的是,当我选中第一个复选框时,进度条值将更改为复选框值,当我选中第二个复选框时,进度条值必须增加第二个复选框值,依此类推

这是我的 JavaScript 代码

$(document).ready(function() {
  $('.progress').change(function(event) {
    var progress_value = $(this).val();
    var newval = progress_value;
    if ($(this).is(':checked')) {
      $('.progress-bar').css("width", function(i) {
        while(newval < 100) {
          return newval+"%";
          newval+=progress_value;
        }
      });
    } else {
      $('.progress-bar').css("width", function(i) {
        do {
          newval -= progress_value;
          return newval+"%";
        } while(newval >= progress_value);
      });
    }
  });
});

也许试试这个:

Bootply : http://www.bootply.com/106527 http://www.bootply.com/106527

Js :

$('input').on('click', function(){
  var valeur = 0;
  $('input:checked').each(function(){
       if ( $(this).attr('value') > valeur )
       {
           valeur =  $(this).attr('value');
       }
  });
  $('.progress-bar').css('width', valeur+'%').attr('aria-valuenow', valeur);    
});

HTML :

 <div class="progress progress-striped active">
        <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
        </div>
    </div>
<div class="row tasks">
        <div class="col-md-6">
          <p><span>Identify your campaign audience.</span>Who are we talking to here? Understand your buyer persona before launching into a campaign, so you can target them correctly.</p>
        </div>
        <div class="col-md-2">
          <label>2014-01-29</label>
        </div>
        <div class="col-md-2">
          <input name="progress" class="progress" type="checkbox" value="10">
        </div>
        <div class="col-md-2">
          <input name="done" class="done" type="checkbox" value="20">
        </div>
      </div><!-- tasks -->

<div class="row tasks">
        <div class="col-md-6">
          <p><span>Set your goals + benchmarks</span>Having SMART goals can help you be
sure that you’ll have tangible results to share with the world (or your
boss) at the end of your campaign.</p>
        </div>
        <div class="col-md-2">
          <label>2014-01-25</label>
        </div>
        <div class="col-md-2">
          <input name="progress" class="progress" type="checkbox" value="30">
        </div>
        <div class="col-md-2">
          <input name="done" class="done" type="checkbox" value="40">
        </div>
      </div><!-- tasks -->

Css

.tasks{
    background-color: #F6F8F8;
    padding: 10px;
    border-radius: 5px;
    margin-top: 10px;
}
.tasks span{
    font-weight: bold;
}
.tasks input{
    display: block;
    margin: 0 auto;
    margin-top: 10px;
}
.tasks a{
    color: #000;
    text-decoration: none;
    border:none;
}
.tasks a:hover{
    border-bottom: dashed 1px #0088cc;
}
.tasks label{
    display: block;
    text-align: center;
}
$(function(){
$('input').on('click', function(){
  var valeur = 0;
  $('input:checked').each(function(){
       if ( $(this).attr('value') > valeur )
       {
           valeur =  $(this).attr('value');
       }
  });
  $('.progress-bar').css('width', valeur+'%').attr('aria-valuenow', valeur);    
});

});
.tasks{
	background-color: #F6F8F8;
	padding: 10px;
	border-radius: 5px;
	margin-top: 10px;
}
.tasks span{
	font-weight: bold;
}
.tasks input{
	display: block;
	margin: 0 auto;
	margin-top: 10px;
}
.tasks a{
	color: #000;
	text-decoration: none;
	border:none;
}
.tasks a:hover{
	border-bottom: dashed 1px #0088cc;
}
.tasks label{
	display: block;
	text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

 <div class="progress progress-striped active">
        <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
        </div>
    </div>
<div class="row tasks">
        <div class="col-md-6">
          <p><span>Identify your campaign audience.</span>Who are we talking to here? Understand your buyer persona before launching into a campaign, so you can target them correctly.</p>
        </div>
        <div class="col-md-2">
          <label>2014-01-29</label>
        </div>
        <div class="col-md-2">
          <input name="progress" class="progress" type="checkbox" value="10">
        </div>
        <div class="col-md-2">
          <input name="done" class="done" type="checkbox" value="20">
        </div>
      </div><!-- tasks -->

<div class="row tasks">
        <div class="col-md-6">
          <p><span>Set your goals + benchmarks</span>Having SMART goals can help you be
sure that you’ll have tangible results to share with the world (or your
boss) at the end of your campaign.</p>
        </div>
        <div class="col-md-2">
          <label>2014-01-25</label>
        </div>
        <div class="col-md-2">
          <input name="progress" class="progress" type="checkbox" value="30">
        </div>
        <div class="col-md-2">
          <input name="done" class="done" type="checkbox" value="40">
        </div>
      </div><!-- tasks -->
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

选中复选框时动态更改引导程序进度条值 的相关文章

随机推荐

  • 尽管提供了接受属性,Antd 上传程序仍然接受所有文件

    我正在使用 antd 拖放组件https ant design components upload components upload demo drag https ant design components upload compone
  • Flexbox 顺序和选项卡导航

    我想用显示 柔性改变order的 div 与line类 但我想保持这个 TAB 导航顺序 A B C D 正如您在代码片段中看到的 第一个示例工作正常 DOM 序列与 Order 相同 但在第二个示例中 选项卡遵循 DOM 序列 不使用 j
  • 编译一个快速修复程序

    我正在尝试使用 QuickFix 库通过 FIX 协议连接到代理 我刚刚使用他们提供的文档构建了库 并立即使用他们的示例代码 include quickfix FileStore h include quickfix FileLog h i
  • MongoDB 获取聚合查询的executionStats

    我正在寻找一种方法来检索executionStats用于聚合 当使用 find 时 我可以通过使用轻松检索它们explain https docs mongodb com manual reference explain results 输
  • 防止浏览器缓存 AJAX 调用结果

    看起来如果我使用加载动态内容 get 结果缓存在浏览器中 在 QueryString 中添加一些随机字符串似乎可以解决这个问题 我使用new Date toString 但这感觉就像是黑客攻击 还有其他方法可以实现这一目标吗 或者 如果唯一
  • 如何使用Java读取带有部分的配置文件[重复]

    这个问题在这里已经有答案了 给定一个包含以下内容的文件 upper a A b B words 1 one 2 two 如何参考它们的标头访问这些键 值 Java 的 Properties 类仅处理无节文件 使用 ini4j 库 链接教程
  • C 缓冲区溢出 - 为什么有恒定数量的字节会引发段错误? (Mac OS 10.8 64 位,clang)

    我正在试验 C 中的缓冲区溢出 发现一个有趣的怪癖 对于任何给定的数组大小 似乎有一定数量的溢出字节可以在 SIGABRT 崩溃之前写入内存 例如 在下面的代码中 10 字节数组可以溢出到 26 字节 然后在 27 处崩溃 同样 20 字节
  • 按住按钮“重复射击”

    我已经提到了无数关于按住按钮的其他问题 但与 Swift 相关的问题并不多 我有一个使用 touchUpInside 事件连接到按钮的函数 IBAction func singleFire sender AnyObject code 还有另
  • 我的随机化代码无法离线工作

    我是一个 php 菜鸟 我只是根据我在网上找到的其他一些脚本制作了一个小脚本 它从名为 Random 的文件夹中随机选取 3 张图像并显示它们 当我在线运行脚本时它可以工作 但是当我尝试在 xampp 上离线运行它时 我收到此错误 注意 未
  • UITableView 的第一行在顶部栏下被截断

    我有一个UITabBarController有两个UITableViews 全部都是在故事板中创建的 问题是 在第二个表视图中 表的前几行位于顶栏下方 第一个表视图不会发生这种情况 即使我更改视图的顺序 第一个视图将完美工作 第二个视图将呈
  • 派生类构造函数在 python 中如何工作?

    我有以下基类 class NeuralNetworkBase def init self numberOfInputs numberOfHiddenNeurons numberOfOutputs self inputLayer numpy
  • R:使用 spplot 地图中的自定义调色板

    我正在努力使用在多个多边形上引入自定义调色板spplot来自sp包裹 我正在绘制几个字段并希望显示我的评级 其值可以为 0 1 2 4 或 5 我需要为此使用自定义颜色 我尝试的是 spplot Map zcol Rating col re
  • 仅在现有 iOS 应用程序中对某些视图使用 React Native

    是否可以仅对项目中的一个视图使用 React Native 我已经成功为特定的 iOS 应用程序屏幕添加了 React 视图 使用 与现有 iOS 项目集成 文档中的说明 但我不知道如何从该屏幕获取数据并调用其他 objective c 代
  • VB.Net Xml 反序列化为类

    我在尝试将一些 XML 反序列化到我创建的类中时遇到了一些问题 我得到的错误是 There is an error in XML document 1 2 at System Xml Serialization XmlSerializer
  • MongoDB索引/RAM关系

    我即将在一个新项目中采用 MongoDB 我选择它是为了灵活性 而不是可扩展性 因此将在一台机器上运行它 从文档和网络帖子中我一直读到所有索引都在 RAM 中 这对我来说没有意义 因为我的索引很容易大于可用 RAM 的量 谁能分享一些关于索
  • 如何使用java获取xml节点的属性值

    我有一个 xml 如下所示
  • 我怎样才能让 Modelsim 警告我有关“X”信号的信息?

    我正在使用 Modelsim 进行大型设计 我已经了解了 modelsim 模拟的工作方式 我想知道 是否有一种方法可以在 modelsim 在仿真阶段评估信号并发现它是红色信号 即 X 时向我发出警告 要知道 不可能列出设计的所有信号并一
  • Rails 4:SQLException:没有这样的表:

    我在 Rails4 中运行以下命令 bundle exec rake db migrate 201405270646 AddAttachmentImageToPins 迁移 change table pins 耙子中止 StandardEr
  • 通过扬声器的 AVAudioPlayer

    我得到以下代码 id init if self super init UInt32 sessionCategory kAudioSessionCategory MediaPlayback AudioSessionSetProperty kA
  • 选中复选框时动态更改引导程序进度条值

    我正在尝试制作一个带有引导进度条的动态清单 这是我的标记代码 div class progress progress striped active div class progress bar div div div class row t