javascript 不会运行

标签 javascript jquery html css

我正在尝试使用 javascript 创建一个简单的投票/投票程序,我尝试在 xammp 上运行它以查看它是否需要在 Web 服务器上执行但没有成功。我是否需要包含除 vote.js 之外的任何脚本 js 文件,如 jquery 或其他?我不确定。

谁能帮忙谢谢。

html

<!DOCTYPE html>
<html>

<head>
<title>Vote</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="vote.js"></script>
</head>

<body>
<div class="content">
    <h3 class="title">Who's better ?</h3>
<ul>
    <li class="option" id="option_1">
        Messi

        <p class="score" id="score_1">0</p>

        <div class="progressbar">
        </div>
    </li>

    <li class="option" id="option_2">
        Ronaldo

        <p class="score" id="score_2">0</p>

        <div class="progressbar">
        </div>
    </li>
   </ul>
   </div>
</body>
</html>

CSS

.content {
background-color: #5C5C5C;
height: 500px;
width: 600px;
font-family: CorpidRegular,Arial,Helvetica,sans-serif;
color: #fff;
font-weight: normal;
font-size: 1.5rem;
}
.progressbar_1 {
width: 400px;
border-radius: 0px;
margin-left: 100px;
}
.progressbar_2 {
width: 400px;
border-radius: 0px;
margin-left: 100px;
}

h3{    
text-align: center;
padding: 40px;
margin: 0px;
font-weight: normal;
}
ul{
list-style-type: none;
display: inline;
padding: 0px;
}
.option:first-child {
background: blue;
}
.option {
background: black;
}
li{
margin: 0px;
padding: 0px;
text-align: center;
color: #fff;
cursor: pointer;
}
li:hover {
color: yellow;
}

js

var totalVotes = 0;

$('.option').click(function() {
var $this = $(this);

// store voting value in data-voting
if (!$this.data('voting'))
    $this.data('voting', 0);

var voting = parseInt($this.data('voting'), 10);
voting++;
totalVotes++;

$this.data('voting', voting);

updateProgressBars();
});

function updateProgressBars()
{
$('.option').each(function()
    {
    var $this = $(this);
    var voting = parseInt($(this).data('voting'), 10);
    var pct = Math.round((voting / totalVotes) * 100);

    if (isNaN(voting)) voting = 0;
    if (isNaN(pct)) pct = 0;

    $this.find('progressbar').progressbar({value: pct});
    $this.find('.score').html(voting + ' of ' + totalVotes + ' (' + pct + '%)');
    });
}

最佳答案

你只关闭了html标签,没有打开标签

关于javascript 不会运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26577750/

相关文章:

javascript - 循环数据表行

javascript - 使 Webpack 输出文件相对于输入文件

javascript - 访问三元数组中对象的属性

javascript - html 和 php 视频需要很长时间才能缓冲

javascript - 尝试使用 jQuery 检索部分 URL;它有效,但未返回字符串

javascript - 将 angularjs 模块导出为 es6 模块

javascript - 如何将无限滚动添加到 BigCommerce 类别页面

javascript - 如何在 html Canvas 上找到三 Angular 形的面积?

图像上的 Javascript 动画

javascript - 一个简单的 .click() 在 Javascript 中不起作用