繁体   English   中英

HTML jQuery .load()无法正常工作

[英]HTML jQuery .load() not working

我正在尝试在引导HTML中使用jQuery .load()函数,但无法正常工作。

我想导入另存为制表符内容(#accueil)中的另一些HTML(accueil.html)中的部分。

请在下面找到我要包括的索引代码和accueil.html。

<!DOCTYPE html> <html>   <head>
    <!-- En-tete de la page -->
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Paul's website</title>
    <meta name="description" content="Le site de Paul">

    <!-- links -->
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <!-- Bootrap & jQuery -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <link href='http://fonts.googleapis.com/css?family=Bitter' rel='stylesheet' type='text/css'>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->   </head>   <body>
    <div class="container-fluid">
      <!-- Corps de la page -->
      <div class="row">
        <header class="page-header hidden-xs col-sm-12">
          <h1>Site de Paul</h1>
        </header>
      </div>
      <div class="row">
      <section>
        <nav class="navbar navbar-default navbar-left" role="navigation">
          <!-- Brand and toggle get grouped for better mobile display -->
          <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand visible-xs" href="#">Site de Paul</a>
          </div>
          <!-- Collect the nav links, forms, and other content for toggling -->
          <div class="collapse navbar-collapse  navbar-ex1-collapse">
            <ul class="nav nav-pills nav-stacked">
              <li class="active"><a href="#accueil" data-toggle="tab">
                <span class="glyphicon glyphicon-home" aria-hidden="true"></span>
                Accueil</a>
              </li>
              <li><a href="#programme" data-toggle="tab">
                <span class="glyphicon glyphicon-glass" aria-hidden="true"></span>
                Programme</a>
              </li>
              <li><a href="#hotel" data-toggle="tab">
                <span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span>
                Lieu & Hotels</a>
              </li>
              <li><a href="#liste" data-toggle="tab">
                <span class="glyphicon glyphicon-gift" aria-hidden="true"></span>
                Liste de Mariage</a>
              </li>
              <li><a href="#album" data-toggle="tab">
                <span class="glyphicon glyphicon-camera" aria-hidden="true"></span>
                Album photo</a>
              </li>
              <li><a href="#covoiturage" data-toggle="tab">
                <span class="glyphicon glyphicon-road" aria-hidden="true"></span>
                Covoiturage</a>
              </li>
              <li><a href="#contacts" data-toggle="tab">
                <span class="glyphicon glyphicon-comment" aria-hidden="true"></span>
                Contacts</a>
              </li>
            </ul> 
          </div>
        </nav>
        <div class="tab-content col-sm-9" style="border:1px solid red;">
          <div class="tab-pane active in" id="accueil">
            <!-- Accueil Tab-content -->
          </div>
          <div class="tab-pane" id="programme"><h2>Programme</h2></div>
          <div class="tab-pane" id="hotel"><h2>Hotel</h2></div>
          <div class="tab-pane" id="liste"><h2>Liste</h2></div>
          <div class="tab-pane" id="album"><h2>Album photo</h2></div>
          <div class="tab-pane" id="covoiturage"><h2>Covoiturage</h2></div>
          <div class="tab-pane" id="contacts"><h2>Contacts</h2></div>
        </div>
      </section>
      </div>
      <div class="row">
        <footer class="well col-xs-12">
          <p style="text-align:center;">- Paul's tests -</p>
        </footer>
      </div>
    </div>
    <!-- Scripts to load at the end -->
    <!-- Set JQuery env -->
    <script   src="http://code.jquery.com/jquery-2.2.4.js"   integrity="sha256-iT6Q9iMJYuQiMWNd9lDyBUStIq/8PuOW33aOqmvFpqI="   crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

    <!-- functions jQuery -->
    <script type="text/javascript">
      $(function(){
        $("#accueil").load("accueil.html");
      });
    </script>

  </body> </html>

要在“ #accueil”标签中添加的HTML

<section  class="tab-section">
  <h1>Bienvenue a tous</h1>
  <div id="welcomeTxt">
    <figure class="">
      <img id="imgAccueil" src="img/accueil.jpg" alt="Photo accueil" title="Welcome to our website">
      <figcaption>Photo champs de tournesol</figcaption>
    </figure>

    <article class="">
      <p>
        Nous sommes très heureux de vous acceuillir sur notre site!
      </p>
    </article>
  </div>
</section>

除了链接>>> <a href="#accueil" data-toggle="tab">我在您提供的HTML中的任何地方都未看到“ #accueil”被引用

也许在您要加载该内容的其中一个<div id="accueil"></div>中创建一个?

编辑:当您在jQuery中调用$('#myId')。load ...时,您基本上告诉jQuery抓取该DOM元素并将加载的内容粘贴到该元素中。

你应该尝试这样的事情

$( "#accueil" ).load( "accueil.html .tab-section" );

这是一个演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM