English 中文(简体)
Java文或 j正冲破我的 j印变。 我怎么回想?
原标题:Javascript or jQuery is caching my javascript variable. How do I reset this?

我有这样的呼吁:

    $( a.delete_task ).live( click , function() {
      $this = $(this);

      function deleteFunction(){            

        var obj = $this.parents( .task );
        $(obj).addClass( highlighted );

        $.post($this.attr( href ), { _method:  delete  }, function(data) {
          if ( $single_item_collection == true ) {
          } else {
          };
        });
      };

      SSK.confirm_delete($this, deleteFunction, "task");
      return false;
    });

接着,我使用我的<代码>deleteFunction()并将其输入delete_confirmation:

$(function(){
  window.SSK = new(Class.extend({
  confirm_delete: function(obj, action, label){
    $(".confirm-deletion").live("click", function(){
      action.call(obj);
      $(this).parents("#delete-message").fadeOut();
      return false;
    });
  }, 

问题是,我第一次点击它。 当我第二次点击时,它通过第一个<代码>$(this)和第二个$(this)。 同样,当我第三次点击另一个项目时,它尝试和通过这三个项目。

具体地说,是打上<代码>$(本)。 as。 每次都采用这种方法。

Confirm delete as a function creates a popup and passes the method of the link you originally clicked to it as the variable obj.

接着,如果你点击确认,情况如下:

    $(".confirm-deletion").live("click", function(){
      action.call(obj);
      $(this).parents("#delete-message").fadeOut();
      return false;
    });
最佳回答

每次用户点击删除_task 时,你都会把点击事件添加到元件确认-替代上。 因此,点击事件造成多次射击,实际上增加了多次。

问题回答

No, it s surely not crazy caching. Read https://developer.mozilla.org/en/JavaScript/Reference/Operators/this and rewrite confirm_delete and/or deleteFunction.

我确信,你需要在点击手关闭时将<条码>(本项)贴在沥滤值中,然后在<条码>上使用。





相关问题
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.

热门标签