【发布时间】:2017-01-25 01:06:53
【问题描述】:
我尝试创建一个类似于 reddit 中的投票系统。每个帖子都有两个按钮,每个与特定帖子关联的按钮都有不同的 id。我已将所有按钮的图像设置为无色箭头。
<div class="details">
<li>AAAAA</li></div>
<div id="voting">
<div class="vote-up"><button id="up-e/aaaaa" title="Up" class="up " onclick="vote('e/aaaaa', 1,'swap')" ></button>
</div>
<div id="vote-score">
<div id="score-e/aaaaa"><span>51</span></div>
</div>
<div class="vote-down"><button id="down-e/aaaaa" title="Down" class="down" onclick="vote('e/aaaaa', 0, 'swap')" ></button>
</div></div>
</div>
<div id="content">
<div class="details">
<li>MIT</li></div>
<div id="voting">
<div class="vote-up"><button id="up-e/mit" title="Up" class="up " onclick="vote('e/mit', 1,'swap')" ></button>
</div>
<div id="vote-score">
<div id="score-e/mit"><span>40</span></div>
</div>
<div class="vote-down"><button id="down-e/mit" title="Down" class="down" onclick="vote('e/mit', 0, 'swap')" ></button>
</div></div>
</div>
这是运行良好的投票系统。 这种风格
vote-up button{
height: 32px;
width: 32px;
border: 0;
background: url("upvote.png");
}
.vote-down button
{
height: 32px;
width: 32px;
border: 0;
background: url("downvote.png");
}
到目前为止,每个帖子都有向上和向下箭头。当用户单击按钮时,按钮的图像应该改变,因为我已经在 jquery 中编写了这个函数
function vote(id, vote, userid){
if(!logged)
{
alert("You must be logged in to vote");
}
else {
if(vote==1){
$("#up-"+id).css({'background', 'url("upvoted.png")'});
$("#down-"+id).css('background', 'url("downvote.png")');
$("#up-"+id).attr('disabled', true);
$("#down-"+id).attr('disabled', false);
}
else {$("#down-"+id).css('background', 'url("downvoted.png")');
$("#up-"+id).css('background', 'url("upvote.png")');
$("#down-"+id).attr('disabled', true);
$("#up-"+id).attr('disabled', false);
}}
"downvoted.png" 和 "upvoted.png" 存储用户点击按钮时要放置在以前的图像位置的图像。
当我点击按钮时,图像没有改变。
【问题讨论】:
-
您遇到的具体问题是什么?
-
点击按钮后图片没有变化
-
请创建一个 jsbin / jsfiddle 演示页面
-
我导入了蓝色图片而不是原来的箭头,如果用户点击它应该变成红色jsfiddle.net/zLjpjmr1
标签: javascript jquery html css