我嘗試執行以下代碼上:保持點擊次數的記錄頁面上的外部鏈接或內部鏈接
<a href = "http://www.google.com"/ id="external">go to google</a>
<span id="num1"></span>// to show the number of clicks so far.
<a href = "index.php" id="internal">go to home</a>
<span id="num2"></span>>// to show the number of clicks so far.
<script>
$(document).ready(function() {
var count1=0;
var count2=0;
$("#external").click(function(){
count1++;
});
$("#num1").html(count1);
$("#internal").click(function(){
count2++
});
$("#num2").html(count2);
});
</script>
我不知道我做了什麼上面是正確的目的跟蹤每個鏈接上的點擊次數,問題是再次加載頁面時,count變量將被重置爲0,我想知道是否需要將count變量插入數據庫中,還是有更高效如何做到這一點,任何人都可以幫助我,任何幫助將不勝感激!
必須保存在某個地方,目前您的存儲在用戶數鏈接瀏覽器。 – 2011-12-14 19:19:04