i have simple request I'm beginner in jquery so all i want to do is to do
butt开发者_StackOverflow中文版on when i click it increment counter variable and update only label on page not all page also i will use same code to make clock in page thank you
Without you trying some code it is hard to be of specific help, but here is how to read a click, increment a counter, update a label, and call a make clock function.
$(function() {
function incrementCounter() {
var $counter = $('#counter'),
count = parseInt($counter).text());
if (!count) count = 0;
count++;
$counter.text(count);
}
function updateLabel(newText) {
$('label').text(newText);
}
function makeClock() {
// I have no idea what you mean by this but insert your code here.
}
$('button').click(function() {
incrementCounter();
updateLabel();
makeClock();
});
});
The increment one you can do it like this:
<script type="text/javascript" src="jquery-1.6.3.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#button').click(function() {
current = parseInt($('#label').html());
$('#label').html(current+1);
});
});
</script>
<input type='button' value=' Increase! ' id='button' />
Count: <span id='label'>0</span>
精彩评论