2011-09-23 86 views
0

我有簡單的請求 我初學者jQuery的,因此所有我想要做的就是做部分頁面更新

按鈕,當我點擊它增加計數器變量,只更新標籤不 頁所有頁面 我也將使用相同的代碼,以使時鐘 頁謝謝

+0

你的問題很難理解。 – Pointy

回答

0

沒有你想一些代碼,很難成爲具體的幫助,但這裏是如何閱讀點擊,增加一個計數器,更新標籤,並調用make clock功能。

$(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(); 
    }); 
}); 
0

遞增一個,你可以做這樣的:

<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> 
+0

先謝謝你,但是是什麼讓它變得簡單 –

+0

我不明白你想說什麼。如果這不起作用,那麼請向我們展示您想要的html,以便相應地添加jQuery行爲。 – derp

+0

它爲我工作,謝謝 –

相關問題