gpt4 book ai didi

javascript 不会运行

转载 作者:太空宇宙 更新时间:2023-11-03 19:36:54 25 4
gpt4 key购买 nike

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com