English 中文(简体)
怎样才能对带有javascript的对应功能作出限制?
原标题:How can i give a limit to an append function with javascript?

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 我所想的是什么,以便我能够从我的错误中吸取教训;(一) 知道自己的错误,但犹豫不决。

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 ++;
    };
})()

www.un.org/Depts/DGACM/index_spanish.htm

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++; 
});
问题回答

This is straight javascript. You might also consider looking into a framework such as jQuery to make it easier for you.

这假定 but子的超文本为id=“appendButton”

var count = 0;
document.getElementById("appendButton").onClick = function(e) {
     if( count >= 10 ) {
          return false;
     }
     else {
          count ++;
          document.getElementById("id_of_thing_you_append_to").innerHTML += "Whatever you re appending";
     }
}

利用您的变量名称:

var thismany = 0;

appendbutton.onclick = function() {
  if (thismany++ < 10) {
    // append things
  }
};

单价:

appendbutton.onclick = function() {
  if (this.count == undefined) {
    this.count = 0;
  }

  if (this.count++ < 10) {
    // append things
  }
};




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签