Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
i want to create a progress bar with multi color with input filed using bootstrap or other things
when i enter a value in the filed like 50% the progress bar go to 50% if a change the value the progress bar change the value and the color is different between the % green blue red

What I have tried:

input code:
HTML
<input id="txt_percent" name="txt_percent" type="text" placeholder="%" class="form-control input-md">


bootstrap progress bar code:
HTML
<div class="progress">
  <div class="progress-bar progress-bar-success" role="progressbar" style="width:40%">
    40%
  </div>
  <div class="progress-bar progress-bar-warning" role="progressbar" style="width:10%">
   60%
  </div>
  <div class="progress-bar progress-bar-danger" role="progressbar" style="width:20%">
    85%
  </div>
Posted
Updated 30-May-16 0:33am

1 solution

HTML
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">

<!-- 可选的Bootstrap主题文件(一般不用引入) -->
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<div>
	<input type="text" id="value">
	<input type="button" id="btn" value="ok">
</div>
<div class="progress">
  <div class="progress-bar" role="progressbar" aria-valuenow="1" aria-valuemin="0" aria-valuemax="100" style="width: 50%;">
    <span class="sr-only">60% Complete</span>
  </div>
</div>
</div>
<script>
$(function(){
	$('#btn').click(function(){
		var v=$('#value').val();
		
		$('.progress-bar').attr('style',"width:"+v+"%;");
	});
});
</script>
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900