zoukankan      html  css  js  c++  java
  • 一个简单的投票功能

    html代码:

    <html>
     <head>
     </head>
     <body>
     <h3 id='toupiao'>请选择</h3>
    <div id="div">
     1:<input type="radio" name="vote" value="0" onclick="getpiao(this.value)"><br>
     2:<input type="radio" name="vote" value="1" onclick="getpiao(this.value)"></div>
     <table style='display:none' id="table">
     <tr>
     <td>选1:</td>
     <td>
        <input style=" height:20px;background-color:red" value="" id="yes"/>%
     </td>
     </tr>
     <tr>
     <td>选2:</td>
     <td>
        <input style=" height:20px;background-color:blue" value="" id="no">%
     </td>
     </tr>
     </table>
     <script type="text/javascript" src="jquery-1.8.1.min.js"></script>
     <script>
     function getpiao(int)
     {
        $.post("/toupiao/piao.php",{"piao":int},function(data){
                if(data.yes!="" || data.no!=""){
                    var newno = parseInt(data.no);
                    var newyes = parseInt(data.yes);
                    $('#yes').val((newyes/(newno+newyes)*100).toFixed(2));
                    $('#yes').css('width', (newyes/(newno+newyes)*100).toFixed(2)+'px');
                    $('#no').val((newno/(newno+newyes)*100).toFixed(2));
                    $('#no').css('width', (newno/(newno+newyes)*100).toFixed(2)+'px');
                    $('#table').css('display',"block");
                    $('#div').css('display',"none");
                    $('#toupiao').html('投票结果');
                }
        },"json");
     }
     </script>
     </body>
     </html>

    PHP代码:

    <?php
     $piao = $_POST['piao'];
     $filename = "piao.txt";
     $content = file($filename);
     $array = explode("/", $content[0]);
     $yes = $array[0];
     $no = @$array[1];
     if ($piao == 0)
        $yes = $yes + 1;
     if ($piao == 1)
        $no = $no + 1;
     $insertpiao = $yes."/".$no;
     $fp = fopen($filename,"w");
     fputs($fp,$insertpiao);
     fclose($fp);
     echo json_encode(array('yes'=>$yes,'no'=>$no));
     ?>
  • 相关阅读:
    Jmeter后置处理器之Json提取器
    Jmeter体系结构-事务控制器
    一款免费的自动化测试工具:AirtestProject
    jsonpath-rw处理json对象
    MySQL常用SQL
    Git使用
    charles的mock功能
    Django项目之blog表设计(二)
    Django小项目之blog(一)
    selenium无界面浏览器,访问百度搜索为例
  • 原文地址:https://www.cnblogs.com/zxm0125/p/6077373.html
Copyright © 2011-2022 走看看