<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<style>
#dakuang {
width:1000px;
height:30px;
}
#left,
#right {
height:100%;
Float:left;
}
#left {
background-color:red;
/*width:335px;*/
}
#right {
Background-color:cadetblue;
/* width:165px;*/
}
</style>
<body>
<div id= "Dakuang" >
<div id= "left" ></div>
<div id= "right" ></div>
</div>
<input type= "button" value= "Yue Qian" id= "btn1"/>
<input type= "button" value= "Li Qiang" id= "btn2"/>
<script>
var left, right, BTN1, btn2;
var result = 500;
var r1 = 335;
Window.onload = function () {
left = document.getElementById ("left");
right = document.getElementById ("right");
BTN1 = document.getElementById ("btn1");
BTN2 = document.getElementById ("btn2");
Btn1.onclick = function () {
result++;
r1++;
Suan ();
}
Btn2.onclick = function () {
result++;
Suan ();
}
Suan ();
Function Suan () {
var B1 = R1/result;
var num1 = Math.Round (B1 * 100);
left.innerhtml = "0." + num1;
right.innerhtml = "0." + (100-NUM1);
var div = document.getElementById ("Dakuang");
Get the width of a large div
var width = div.offsetwidth;
To figure out the width of the div's left.
var leftwidth = width * B1;
Left.style.width = Leftwidth * B1 + "px";
Right.style.width = (width-leftwidth) + "px";
}
}
</script>
</body>
JavaScript usually small example ⑤ (the exercise of voting effect)