-3

これは私のメインページです

<html>

<head>
  <title></title>
  <style>
  #exp{
    height: 100%;
    width:100%;
    position: absolute;
    left:0;
    top:0;
    background:#00FF00;
  }

  </style>
  <script src="scripts/jquery.js"></script>
  <script>
  $(function(){
  $("#exp").load('aboutus.html');

  })
  </script>

</head>

<body>
<div id="exp">

</div>
</body>

</html>

aboutus.html ページからこのコンテンツをロードしたい そのページのコンテンツは

<div style="height:100%;width:100%;position:absolute;left:0px;top:0px">Hai</div>

load、get、.html などを試しましたが、どれも機能していません。php を含めたくない

試した方法

$("#exp").load('aboutus.html');
$("#exp").get('aboutus.html');
$("#exp").html(url(aboutus.html'));
4

2 に答える 2

0

これを行う 1 つの方法は、jquery を使用して AJAX 呼び出しを使用することです。

about ページを JSON コールバック関数にラップするだけです。詳細は下記参照

メインページコード

<html>
<head>
<title></title>
<style>
#exp {
height: 100%;
width:100%;
position: absolute;
left:0;
top:0;
background:#00FF00;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
jQuery(function(){
jQuery.getJSON('about.php?callback=?',function(data){
if(data.status == 'success') {
        jQuery('#exp').html(data.html);
    }
});
})
</script>
</head>
<body>
<div id="exp"> </div>
</body>
</html>

About.PHPページ

<?php
$html .=<<<HTML
    <div style="height:100%;width:100%;position:absolute;left:0px;top:0px">Hai</div>
HTML;
$strippedHTML = str_replace(array("\r\n", "\r", "\n", "\t"), ' ', $html);
echo $_GET['callback'] . '({"status":"success", "html":"' . addslashes(trim($strippedHTML)) . '"})';
?>
于 2013-05-13T17:07:17.363 に答える