weixin_33696106
weixin_33696106
2011-02-22 09:31
采纳率: 0%
浏览 33

将HTML内容加载到DIV中

I am trying to load a HTML file into a DIV and access that whenever i need. This should be done once when loading the script and i can access this no.of time in my code. The HTML contains lots of divs in it and i want to get particular div from the loaded content. Here is my code $("#contentdiv").load("message.html #divname");

can u tell me how to get rid from this

Thanks in advance

图片转代码服务由CSDN问答提供 功能建议

                    

我正在尝试将HTML文件加载到DIV中,并在需要时进行访问。 加载脚本时应该执行一次,我可以访问此编号 我的代码中的时间。 HTML中包含很多div,我想得到 加载内容中的特定div。 这是我的代码 $(“#contentdiv”)。load(“ message.html #divname”);

你能告诉我如何摆脱这种情况吗

预先感谢     

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • weixin_33744141
    weixin_33744141 2011-02-22 09:32

    Load the page, when loaded, get the div you want, and insert it into your contentdiv.

    $.ajax({ url: 'message.html', 
             success : function(data) { 
                           $('#contentdiv').html($(data).find('#divname')); 
                        }
    };
    
    点赞 评论
  • weixin_33735676
    weixin_33735676 2011-02-22 09:34

    try this:

    $("#contentdiv").html($(message.html).find("#divname"));
    
    点赞 评论
  • csdnceshi74
    7*4 2011-02-22 09:38

    From your question I understood that u want to select a particular div from the response html which will be loaded on #contentdiv.

    Its better to access $('#contentdiv->ur div name').html(); or $('#contentdic .div').html() . here .div is a css class

    点赞 评论

相关推荐