The example in this article describes how to implement three voting methods in JavaScript and shares it with everyone for your reference. The details are as follows:
1. js column voting chart
Rendering:
Implementation code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>js柱状投票图</title> <style type="text/css"> body { font-weight:bold; color:#fff; font-size:16px; font-family:Arial, Helvetica, sans-serif; background-color:#000000;} .zhu { margin-top:100px; width:420px; position:relative;} .good { width:200px; position:absolute; bottom:0; left:0; text-align:center; background-color:#f00; height:50px;} .bad { width:200px;position:absolute; bottom:0; right:0; text-align:center; background-color:#009900; height:50px;} .and {} </style> <script type="text/javascript"> //innerHTML 属性设置或返回表格行的开始和结束标签之间的 HTML。 //value 属性可设置或返回单选按钮的 value 属性的值。 //所有css在DOM结构里面都是字符型的 没有数字型的 function TouPiao(){ var good= parseInt(document.ballot.good_num.value); var bad= parseInt(document.ballot.bad_num.value); var sum= good+bad; var sum_g=Math.round(good/sum*100); var sum_b=Math.round(bad/sum*100); document.getElementByIdx_x_x_x("and").innerHTML = "总数为:"+sum+"票"; document.getElementByIdx_x_x_x("g").innerHTML = "好评"+sum_g+"%"; document.getElementByIdx_x_x_x("b").innerHTML = "差评:"+sum_b+"%"; document.getElementByIdx_x_x_x("g").style.height = sum_g+"px"; document.getElementByIdx_x_x_x("g").style.marginTop = (sum_g-100)+"px"; document.getElementByIdx_x_x_x("b").style.height = sum_b+"px"; document.getElementByIdx_x_x_x("b").style.marginTop = (sum_b-100)+"px"; } </script> </head> <body> <form action="" method="get" name="ballot"> 好评票数:<input name="good_num" type="text" /><br /> 差评票数:<input name="bad_num" type="text" /><br /> <input name="bt" type="button" value="提交" onclick="TouPiao()" /> </form> <div class="zhu"> <div class="good" id="g">好评50%</div> <div class="bad" id="b">差评50%</div> </div> <div class="and" id="and">总数为0票</div> </body> </html>
2. JS voting
Rendering:
Implementation code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>投票 </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <mce:style><!-- .voteresult{ margin: 2px; margin-top: 5px; display: block; float: left; width: 250px; height: 10px; background-color: #EEE; overflow: hidden; } .style3{ background-color: #666666; } --></mce:style><style mce_bogus="1"> .voteresult{ margin: 2px; margin-top: 5px; display: block; float: left; width: 250px; height: 10px; background-color: #EEE; overflow: hidden; } .style3{ background-color: #666666; } </style> <mce:script type="text/javascript"><!-- var total_vote = 0; var lq_vote = 0; var zq_vote = 0; var ppq_vote = 0; function vote(){ var selectItem = 0; var items = document.getElementsByName("item"); for(i = 0; i < items.length; i++){ if(items[i].checked){ selectItem++; total_vote++; switch(parseInt(items[i].value)){ case 1: lq_vote++;break; case 2: zq_vote++;break; case 3: ppq_vote++;break; } } } if(selectItem <= 0){ alert("请先选择您喜欢的运动"); return; } var lq_num = new Number(lq_vote/total_vote); var zq_num = new Number(zq_vote/total_vote); var ppq_num = new Number(ppq_vote/total_vote); alert("投票成功"); setSpanWidth(lq_num, 1); setSpanWidth(zq_num, 2); setSpanWidth(ppq_num, 3); for(i = 0; i < items.length; i++){ items[i].checked = false; } } //设置投票结果显示 function setSpanWidth(vote_num, type){ var _width = new Number(250*vote_num); var _span = document.getElementByIdx_x_x_x("span" + type); var _span1 = document.getElementByIdx_x_x_x("span1" + type); //alert(_span.style.width); _span.style.width = _width.toFixed(0); var _percent = new Number(100*vote_num); _span1.innerHTML = _percent.toFixed(1) + "%"; } // --></mce:script> </HEAD> <BODY> 你喜欢的运动: <br> 篮球 <input type="checkbox" name="item" value="1"> 足球 <input type="checkbox" name="item" value="2"> 乒乓球 <input type="checkbox" name="item" value="3"> <br> <input type="button" value="提 交" onclick="vote();"> <br> <br> <table> <tr> <td colspan=3><b>投票结果</b></td> </tr> <tr> <td>篮球</td> <td><div class="voteresult"><span id="span1" class="style3" style="width: 0px;"></span></div></td> <td><span id="span11">0%</span><td> </tr> <tr> <td>足球</td> <td><div class="voteresult"><span id="span2" class="style3" style="width: 0px;"></span></div></td> <td><span id="span12">0%</span><td> </tr> <tr> <td>乒乓球</td> <td><div class="voteresult"><span id="span3" class="style3" style="width: 0px;"></span></div></td> <td><span id="span13">0%</span><td> </tr> </table> </BODY> </HTML>
3. Voting
Rendering:
Implementation code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <style type="text/css"> body{ font-size:12px;} </style> <script language="javascript"> function add(txt) { var abc = document.getElementByIdx_x("abc"); abc.innerHTML = parseInt(abc.innerHTML) + 1; } </script> </head> <body> <table width="50" height="50" border="1" cellpadding="0" cellspacing="0"> <tr> <td align="center" valign="middle"><div id="abc">0</div></td> </tr> <tr> <td align="center" valign="middle"><a href="#" onclick="add(1)">投一票</a></td> </tr> </table> </body> </html>
The above is the entire content of this article, I hope it will be helpful to everyone’s study.

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
