jQuery 可调整大小不适用于 ajax 加载的内容

发布于 2024-09-29 17:02:28 字数 652 浏览 0 评论 0原文

我的页面上有以下 div:

<div id="container">
<div id="resizable">some content</div>
</div>

我有以下函数来使其可调整大小:

$(function(){
   $('div#resizable').resizable();
});

直到这里一切正常,并且我在 div 的右下角调整了大小句柄,但是单击函数后,内部 div 会再次从服务器加载:

$('#button').live('click',function(){
    $.ajax({
       url:"myurl",
       type:"post",
       success:function(data)
      {
         $("#container").html(data);
         $("div#resizable").resizable();
      }
     });
});

尽管我在 ajax 回调中调用可调整大小的函数,但它似乎不起作用。我在 ajax 加载的 div 的右下角看不到调整大小手柄。 id 是对的,一切都一样。可能是什么问题?

I have following div on my page:

<div id="container">
<div id="resizable">some content</div>
</div>

I have following function to make it resizable:

$(function(){
   $('div#resizable').resizable();
});

Till here everything works fine and I have resize handle in bottom right corner of the div, but on click of function the inner div is loaded again from the server:

$('#button').live('click',function(){
    $.ajax({
       url:"myurl",
       type:"post",
       success:function(data)
      {
         $("#container").html(data);
         $("div#resizable").resizable();
      }
     });
});

Even though I'm calling resizable function in ajax callback but it doesn't seem to work. I can't see resize handle in bottom right corner of ajaxically loaded div. The id is right everything is same. What might be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

对不⑦ 2024-10-06 17:02:28

HTML 元素中的 ID 在 HTML 页面中必须是唯一的。相反,您可以对每个您想要调整大小的元素使用类名“可调整大小”。

当您更改为可调整大小的类时,jquery 命令必须更改为:

$("div.ressized").ressized();

井号 (#) 更改为点 (.)

ID in an HTML element must be unique in an HTML page. Instead you could use the classname 'resizable' for every element you wat to be resizable.

When you change to the class resizable the jquery command has to be changed to:

$("div.resizable").resizable();

The hash (#) is changed into a dot (.)

记忆消瘦 2024-10-06 17:02:28

其实这是我的错误。我在一个调用的回调方法中进行了两次 ajax 调用,我添加了 .ressized 方法,但在另一个调用中我没有添加。

Actually it was my mistake. I had two ajax calls in callback method of one call I added .resizable method but in the other I didn't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文