jQuery将html特定的div加载到网页中 [英] jQuery load html specific div into webpage

查看:140
本文介绍了jQuery将html特定的div加载到网页中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有问题

单击时得到四个链接,我想将外部html页面的内容加载到称为content的div中,该div向下滑动并显示外部html页面的内容,但是我想使用链接中的href进行加载在外部html页面中的特定div标签中..我差一点就错过了最后一部分..我似乎无法在我的jquery加载语句中使用我的变量.

got four links when clicked i want to to load in content from an external html page into a div called content which slides down and shows the content from the external html page, but I want to use the href from the links to load in specific div tags from the external html page.. I'm nearly there just missing the final part.. I cant seem to use my variable inside my jquery load statement..

这是香港专业教育学院到目前为止的成果.

this is what ive got so far..

    $("#services a").click(function(){
     var href = $(this).attr("href");
      console.log(href)
      $('#content').slideToggle(function(){
       $("#content").load("services.html" + href); 
      });
    return false;
    });

如果有人能指出我如何在选择其他链接时向后滑动内容div,然后显示该链接的内容,那将是很好的.

also if anyone could point me how to slide the content div back when selecting a different link and then show that content for that link.. would be great..

谢谢大家.

推荐答案

假设href是正确的并且与选择器相同,则您缺少空格:

Supposing the href is correct and is the same as a selector, you're missing a space:

$("#services a").click(function(){
     var href = $(this).attr("href");
     $('#content').slideToggle(function(){
         $("#content").load("services.html " + href); 
                      //                  ^^^ space needed here 
     });
     return false;
});

这是因为load()的正确语法是

$("#content").load("services.html #IdOfelementToLoad"); 
//    ^^                ^^       ^         ^^
//  container         filename  space    selector for filter

文档

这篇关于jQuery将html特定的div加载到网页中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆