English 中文(简体)
页: 1 怀孕箱内没有工作的 Qu子—— in脏问题
原标题:jQuery inside fancy box ajax not working -- init problems

我的守则是打开通过加亚装一页的轮胎箱:

$( tr.record ).click(function() {
    var record_id = $(this).attr("id");
    var link =  http://  + window.location.hostname +  /expenses/expenses_edit/  + record_id;
    $.fancybox({
         transitionIn :  fade ,
         transitionOut :  none ,
         type :  ajax ,
         href : link,
         onClosed : function() {
            parent.location.reload(true);
        }
    });
    $.bind("submit", function() {

        $.fancybox.showActivity();

        $.ajax({
            type: "POST",
            cache: false,
            data: $(this).serializeArray(),
            success: function(data) {
                $.fancybox(data);
            }
        });
        return false;
    });
});

轮胎箱内的网页有一种形式,包括有果园的文字领域:

<form>
...

<textarea name="exp_det" cols="90" rows="12" id="exp_det"></textarea>
<span id="charLeft">150</span> characters left

</form>

The parent page loads this via header:

$( #ext_det ).keyup(function() {
    var len = this.value.length;
    if (len >= 150) {
        this.value = this.value.substring(0, 150);
    }
    $( #charLeft ).text(150 - len);
});

因此,问题是,这一char(和其他 j,如鉴定,日期pi)在ancy子内没有工作。 如果该网页没有轮胎箱装满,或者该网页通过轮胎箱装上。

我理解这似乎是一个合理的共同问题,但我尝试了所有解决办法,没有人为我工作。

我受审

  • using diferent IDs for the ajax page
  • placing the char count script at the end of ajax page (it didn t even show
  • on Firebug)
  • placing the char count script as a function within success
  • other crazy iterations

The problem seems related to re-init ing the jQuery functions after the ajax page has loaded, since these elements were not there when the parent page was loaded.

Any suggestions?

最佳回答

You need to either rebind your event handlers once you have loaded content inside the fancy box or use the JQuery.live event binding mechansim. Your problem is occuring because your event handlers are trying to bind to DOM nodes that are not yet loaded, so what you need to do is either use the JQuery.live, which will bind events to elements even when they have not yet loaded OR use a callback function when your content of your fancybox has loaded to bind the event handlers.

$(document).ready(function() {
    $( #ext_det ).live( keyup , function() {

        // code to execute on keyup for element with id #ext_det    

    });
});
问题回答

暂无回答




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

热门标签