我怎么可以给一个限制使用JavaScript追加功能? [英] How can i give a limit to an append function with javascript?

查看:124
本文介绍了我怎么可以给一个限制使用JavaScript追加功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个附加按钮,如果你点击它这不休不休追加。
可以说,我想这个按钮做10次。

让我告诉你在幻想code:对我在想什么,这样我可以从我的错误中学习; (我知道它错了,但嘿IM学习)

  thismany = 1;appendbutton.onClick =thismany = +1;
如果{thismany =< 9}appendbutton.onClick =禁用

在此先感谢


解决方案

 (函数(){
    变种数= 1;
    的document.getElementById(the_node_id)。=的onclick功能(){
        如果(计数大于10){
            返回;
        }
        做东西();
        算上++;
    };
})()

更新

 变种数= 1;
的addEvent(追加,单击功能(/ * * someargument /){
    如果(计数大于10){
        返回;
    }
    //如果你需要传递给函数的参数,
    //你可以将它们添加到匿名之​​一,并通过他们
    //为appendFunction
    appendFunction(/ * someargument * /);
    算上++;
});

I have an append button which appends endlessly if you click it endlessly. Lets say i want this button to do this 10 times.

Let me tell you in fantasy code :p what i was thinking so that i can learn from my mistakes; ( i know its wrong but hey im learning)

thismany = 1;

appendbutton.onClick = "thismany = +1";
if{ thismany = <9}

appendbutton.onClick = disabled

thanks in advance

解决方案

(function(){
    var count = 1;
    document.getElementById("the_node_id").onclick = function(){
        if(count > 10){
            return;
        }
        do_stuff();
        count ++;
    };
})()

UPDATE:

var count = 1;
addEvent(append, "click", function(/* someargument */){ 
    if(count > 10){
        return;
    }
    // if you need arguments that are passed to the function,
    // you can add them to the anonymous one and pass them 
    // to appendFunction
    appendFunction(/* someargument */);
    count++; 
});

这篇关于我怎么可以给一个限制使用JavaScript追加功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆