1

我们如何只计算一个用户点击链接到给定所有链接的时间,以及如果他完成 10 次点击给定链接以打开另一个窗口为他接受一些文本数据并保存,我们如何显示该用户的总点击量.

4

1 回答 1

1

试试这个代码:

<html>
<head>
</head>
<body>
<a href="javascript:void(0)" onclick="countTenClicks()">Click 10 times to open window
</a>
<script>

    var counter = 0;
    function countTenClicks() {
        if (counter > 9) {
            window.open('http://www.google.com');
        }
        else {
            counter++;
        }

    }

</script>

编辑

<html>
 <head>
<title></title>
 </head>
 <body>
<a href="javascript:void(0)" onclick="countTenClicks(this)" id='link1'>Click 10 times
    to open window link1</a> <a href="javascript:void(0)"    onclick="countTenClicks(this)"
        id='link2'>Click 10 times to open window link2 </a>
<script type="text/javascript">

var link1_counter=0;
var link2_counter=0;
/*
  repeate for 10 links

   var for each link
*/
function countTenClicks(sender){

  var linkID = sender.id;
 switch(linkID)
  {
  case link1:
  if (link1_counter>9)
 {
 window.open('http://www.google.com');
 }
  else
 {
 link1_counter++;
 }
  break;
 case link1:
  if (link2_counter>9)
  {
   window.open('http://www.google.com');
  }
else
 {
 link2_counter++;
 }
  break;
/*
 repeate for 10 links
*/

default:
code to be executed if n is different from case 1 and 2
}

}

</script>

于 2012-11-20T10:51:56.817 回答