JavaScript usually small example ⑤ (the exercise of voting effect)

Source: Internet
Author: User

<! 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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.