2017-04-01 11 views
0

私はロードした別のページをクリックして、スライダメニューを表示したいと思います。 firefoxの作品では、私はすべてのブラウザで自分のHTMLを動作させたいですか?手伝っていただけませんか?ありがとう。onClickはChromeで動作していませんか?

のindex.html:

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
</head> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<body> 
<div > 
    <a href="#" id="link1" >Vertical link 1</a> 
</div> 
<div id="content"></div> 
<script> 
    $("#link1").on("click", function() { 
    $("#content").load("test.html"); 
    }); 
</script> 
</body> 
</html> 

はtest.htmlという:

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
</head> 
<body> 
<div> 
    <table> 
     <thead> 
      <tr> 
       <th scope="col">A</th> 
       <th scope="col">B</th> 
       <th scope="col">C</th> 
       <th scope="col">D</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr> 
       <td>1</td> 
       <td>2</td> 
       <td>3</td> 
       <td>4</td> 
      </tr>   
     </tbody> 
    </table> 
</div> 
</body> 
</html> 
+0

それを生産できません。それがうまくいかないところで、どんなフィドルも共有できますか? –

+0

私は質問を改訂しました。私は – Alex

+0

をクリックして別のページを読み込みたいのですか?簡単にtest.htmlをアンカーのhrefに入れることはできませんか?それは利用できませんか? –

答えて

0

コンテンツが動的である場合、それを委任する必要があります

$(document).on("click", "#link1" , function() { 
    console.log('click') 
    $("#content").load("./resources/link1.html"); 
}); 
1

私は、これがなければならないと思います作業!あなたはhttp://api.jquery.com/load/に移動した場合

<div class="wrapper"> 
    <a href="#" id="link1" >Vertical link 1</a> 
    <a href="#" id="link2" >Vertical link 2</a> 
    <a href="#" id="link3" >Vertical link 3</a> 
    <a href="#" id="link4" >Vertical link 4</a> 
</div> 
<div id="content"></div> 

<script> 
    $('document').ready(function() { 
     $('.wrapper').children().on('click', function (e) { 
      e.preventDefault(); 
      $('#content').load($(this).attr('href')); 
     }); 
    }); 
</script> 
+0

Firefoxでは動作しますが、Chromeでは動作しません。これはクロムのエラーです: "XMLHttpRequestはfile:// C:/test/test.htmlをロードできません。クロスオリジン要求は、プロトコルスキーム(http、data、chrome、chrome-extension、https)でのみサポートされています。 – Alex

+0

@alexこれは、ファイルシステムではなくサーバ上で実行することを意味します – Qchmqs

0

あなたは、この行に気づくでしょう:

説明:サーバーからのデータのロードとマッチした要素の中に返されたHTMLを配置します。

基本的に、負荷を使用する場合は、サーバーから起動する必要があります。

のpython3 -m http.server 9000

そして、開いているブラウザとhttp://localhost:9000に移動:

は、コマンドプロンプト上のpython3をインストールしている場合は、これを試してみてください。それが動作するリンクをクリックしてください。

これはどのサーバーからでも行うことができますが、負荷がかかる場合はサーバーからページを起動する必要があります。

これはクロムのみです。

関連する問題