Голосовалка
По учебнику
by ZondArt
HTML
<div id="voter" class="voter">
<span class="down">—</span>
<span class="vote">0</span>
<span class="up">+</span>
</div>
CSS
.voter {
font-family: Consolas, "Lucida Console", monospace;
font-size: 18px;
}
.up, .down {
cursor: pointer;
color: blue;
font-weight: bold;
}
JavaScript
function Voter(options) {
// ... ваш код
$voter = options.elem;
$vote = $voter.find(".vote");
$voter.on("click", ".down", onClickDown);
$voter.on("click", ".up", onClickUp);
function onClickUp(e) {
i = parseInt($vote.text());
$vote.text(++i);
}
function onClickDown(e) {
i = parseInt($vote.text());
$vote.text(--i);
}
this.setVote = function(int){
$vote.text(int);
}
}
var voter = new Voter({
elem: $('#voter')
});
voter.setVote(1);