-5

我们如何知道用户是否至少点击了 10 次链接?如果用户在链接上单击 10 次,则打开一个自动其他窗口以接受来自用户的数据并存储它.....

请使用JS和HTML解决它。

还有我们如何使用 HTML 的“src”标签调用 JS 函数?

4

2 回答 2

2

链接:

    <a onClick="doTheMagic('http://www.google.com/',1);" href="#">Click on it.</a> Your Total Clicked: <span id="timesClicked_1">0</span>; Remaining Total Clicked <span id="timesRequired_1">10</span>
    <br />
    <a onClick="doTheMagic('http://www.facebook.com/',2);" href="#">Click on it.</a> Your Total Clicked: <span id="timesClicked_2">0</span>; Remaining Total Clicked <span id="timesRequired_2">10</span>
    <br />
    <a onClick="doTheMagic('http://www.twitter.com/',3);" href="#">Click on it.</a> Your Total Clicked: <span id="timesClicked_3">0</span>; Remaining Total Clicked <span id="timesRequired_3">10</span>

的JavaScript:

var clickCounter = new Array();
clickCounter[1] = 0;
clickCounter[2] = 0;
clickCounter[3] = 0;

function doTheMagic(src,linkNumber){
    clickCounter[linkNumber]++;
    if(clickCounter[linkNumber] >= 10){
       poptastic(src);
    }
    document.getElementById("timesClicked_" + linkNumber).innerHTML = clickCounter[linkNumber];
    document.getElementById("timesRequired_" + linkNumber).innerHTML = (10 - clickCounter[linkNumber]);
}

var newwindow;
var adParams = {a: '9386380', size: '728x90'};
var size = adParams['size'].split("x");
function poptastic(url){
    var params = [
                'height='+size[0],
                'width='+size[1],
                'fullscreen=no' // only works in IE, but here for completeness
                ].join(',');
    newwindow=window.open(url,'name',params);
    if (window.focus) {newwindow.focus()}
}

jsfiddle

于 2012-11-20T10:15:30.473 回答
0

点击事件。使用它来捕捉鼠标点击并执行 javascript。
请不要在每个单词上使用大写字母。它使您的问题难以阅读。

于 2012-11-20T10:12:13.970 回答