前に書いた記事に続き、jQueryのloadを使いHTMLファイルにある特定のタグを読み込んで表示するプログラムです。
test.html(読み込むHTMLファイル)
<h1>Test</h1> <p>テストです</p>
load.html
load.htmlファイルの.load(‘test.html p’)と設定してtest.htmlのpタグを取得して、div#contentに「テストです」と表示されます。
<script>
$(function() {
$('#content').load('test.html p');
});
</script>
div#contentに結果が表示されます。
<div id="content"></div>
スポンサーリンク

コメント