en.javascript.info/2-ui/5-widgets/5-custom-events/1-voter-events/solution.view/index.html
2015-02-21 00:59:02 +03:00

42 lines
782 B
HTML
Executable file

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
.voter {
font-family: Consolas, "Lucida Console", monospace;
font-size: 18px;
}
.up, .down {
cursor: pointer;
color: blue;
font-weight: bold;
}
</style>
<script src="https://cdn.polyfill.io/v1/polyfill.js?features=CustomEvent,Element.prototype.closest"></script>
<script src="voter.js"></script>
</head>
<body>
<div id="voter" class="voter">
<span class="down"></span>
<span class="vote">0</span>
<span class="up">+</span>
</div>
<script>
var voter = new Voter({
elem: document.getElementById('voter')
});
voter.setVote(5);
document.getElementById('voter').addEventListener('change', function(e) {
alert(e.detail);
});
</script>
</body>
</html>