English 中文(简体)
JQuery用有效载荷取代整个DIV
原标题:JQuery replace entire DIV using .load()

我愿重写一个<条码>与设计;div>,内容是关于“ j”的结局。

我的法典是:

var dialog = jQuery( #divPopup ).dialog({
    autoOpen: false,
    height: 450,
    width: 650,
    modal: true,
    open: function(event, ui) {
        jQuery( body ).css( overflow ,  hidden );
    },
    close: function(event, ui) {
        jQuery( #divPopup ).dialog( destroy ).remove();
        jQuery("#bodyId").load("http://www.xyz.com/ #bodyId");
    }
});

但是,在原有的<代码><div>内添加新的<代码><div>:

<div id="bodyId">
    <div id="bodyId">
        New Response
    </div>
</div>

我愿用新的div .Id取代原有的div

最佳回答

取代:

jQuery("#bodyId").load("http://www.xyz.com/ #bodyId");

......

jQuery("#bodyId").load("http://www.xyz.com/ #bodyId > *");

这是因为你可以在URL之后使用任何选择。 采用<条码> 页: 1 a iv,而不是 d。

你们之所以需要,是因为.load(>>将不会取代一项内容;它将append<>_em>AJAX呼吁该要素的结果。

或者,你可以使用<代码>.get()来装载数据并人工进行选择,例如:

$.get( http://www.xyz.com/ , function(data) {
    var newContent = $(data).find( #bodyId ).children();
    $( #bodyId ).empty().append(newContent);
});

两种方法的例子见:

问题回答

You could also use jquery.get.

$.get( http://www.xyz.com/ , function(data) {
  $( #bodyId ).html(data);
});




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