本文介绍了如何使用 javascript 限制 append 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个追加按钮,如果您无休止地单击它,它就会无休止地追加.假设我希望此按钮执行此操作 10 次.
I have an append button which appends endlessly if you click it endlessly.Lets say i want this button to do this 10 times.
让我用奇幻代码告诉你 :p 我在想什么,以便我可以从错误中吸取教训;(我知道这是错误的,但嘿我正在学习)
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
提前致谢
推荐答案
(function(){
var count = 1;
document.getElementById("the_node_id").onclick = function(){
if(count > 10){
return;
}
do_stuff();
count ++;
};
})()
更新:
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 限制 append 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!