Pages
- Index of Lessons in Technology
- Index of Book Summaries
- Index of Book Lists And Downloads
- Index For Job Interviews Preparation
- Index of "Algorithms: Design and Analysis"
- Python Course (Index)
- Data Analytics Course (Index)
- Index of Machine Learning
- Postings Index
- Index of BITS WILP Exam Papers and Content
- Lessons in Investing
- Index of Math Lessons
- Downloads
- Index of Management Lessons
- Book Requests
- Index of English Lessons
- Index of Medicines
- Index of Quizzes (Educational)
Saturday, March 19, 2022
Knockout based Counter Version 5 (Erroneous)
Code
<!DOCTYPE html>
<html lang="en">
<head>
<title>Sample-Counter</title>
<meta charset="utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://knockoutjs.com/downloads/knockout-3.5.1.js"></script>
<style>
.text-highlighter {
padding: 20px;
}
</style>
</head>
<body>
<div>
<div data-bind="template: { name: 'counterTemplate',
data: count,
afterRender: function() {
setTimeout( function() {}, 1000 )
} }"> </div>
</div>
<script type="text/html" id="counterTemplate">
<h1 data-bind="text: $data" class="text-highlighter" ></h1>
</script>
<button data-bind="click: startIncrementer">Start</button>
</div>
<script>
function ItemViewModel() {
var self = this;
this.count = ko.observable(0);
this.incrementer = function () {
self.count(self.count() + self.increment());
}
this.increment = ko.observable(1)
this.startIncrementer = function () {
for (var i = 0; i < 20; i++) {
setTimeout(this.incrementer, (self.increment() * 1000))
}
}
}
var viewModel = new ItemViewModel();
ko.applyBindings(viewModel);
</script>
</body>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment