Javascript 如何更改投票结果栏的颜色?
我正在用两个结果栏进行民意测验。结果栏都是蓝色的,但当我尝试更改栏的颜色时,它不会更改 我试图寻找其他关于堆栈溢出的答案,(:)但它们似乎不起作用Javascript 如何更改投票结果栏的颜色?,javascript,php,html,jquery,css,Javascript,Php,Html,Jquery,Css,我正在用两个结果栏进行民意测验。结果栏都是蓝色的,但当我尝试更改栏的颜色时,它不会更改 我试图寻找其他关于堆栈溢出的答案,(:)但它们似乎不起作用 <script> function getVote(int) { var xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=function() {
<script>
function getVote(int) {
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("poll").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","poll/study_vote.php?vote="+int,true);
xmlhttp.send();
}
</script>
<div id="poll">
<h2>When studying, do you often find yourself procrastinating?</h2>
<form>
Yes: <input type="radio" name="vote" value="0" onclick="getVote(this.value)"><br>
No: <input type="radio" name="vote" value="1" onclick="getVote(this.value)">
</form>
</div>
</script>
实际的进度条是由浏览器实现的(类似于按钮的方式,如果您以前遇到过CSS问题的话),并且直接用CSS修改比只针对
进度
元素要困难一些。您必须使用特定于供应商的伪元素,例如在Chrome中:
#文件1::-webkit进度值{
背景:粉红色;
}
我相信Firefox需要的CSS是:
#文件1::-moz进度条{
背景颜色:粉红色;
}
您可以在“另请参阅”中找到有关可以应用的其他CSS属性(及其特定于供应商的伪元素)的更多信息靠近底部的部分。我看到了
您希望什么时候更改颜色,还是希望其中一个是蓝色,另一个是不同的颜色?可能会发现这篇文章很有用:@dalelandry我希望它们都是另一种颜色(例如粉色)@RenevanderLende是的,没错。我将元素ID名称更改为#file1和#file2。酒吧颜色变化的CSS在我的帖子上-但它没有正常工作-你可能知道为什么吗?非常感谢!这真的帮了大忙
<?php
$vote = $_REQUEST['vote'];
//get content of textfile
$filename = "poll_result.txt";
$content = file($filename);
//put content in array
$array = explode("||", $content[0]);
$yes = $array[0];
$no = $array[1];
if ($vote == 0) {
$yes = $yes + 1;
}
if ($vote == 1) {
$no = $no + 1;
}
//insert votes to txt file
$insertvote = $yes."||".$no;
$fp = fopen($filename,"w");
fputs($fp,$insertvote);
fclose($fp);
$yesProgress = 100*round($yes/($no+$yes),2);
$noProgress = 100*round($no/($no+$yes),2);
?>
<h2>Result:</h2>
<table>
<tr>
<td>Yes:</td>
<td>
<progress id="file1" max="100" value="<?= $yesProgress ?>">
<?= $yesProgress ?>
</progress>
<?= $yesProgress ?>%
</td>
</tr>
<tr>
<td>No:</td>
<td>
<progress id="file2" max="100" value="<?= $noProgress ?>">
<?= $noProgress ?>
</progress>
<?= $noProgress ?>%
</td>
</tr>
</table>
#poll {
text-align: center;
background-color: #FFDFB2;
border-radius: 2vw;
padding: 10px 50px;
display: inline-block;
}
progress#file[value]::-webkit-progress-bar {
background-color: purple;
border-radius: 2px;
}