jquery学習のhtmlとtextの違い
1297 ワード
html()タグを含むhtmlを表示する
text()は純粋なテキストを表示します
result:
最初のalert出力
2番目のalert出力
This is a heading
This is a paragraph.
This is another paragraph.
This is another paragraph.
This is another paragraph.
text()は純粋なテキストを表示します
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
alert($("div").html());
alert($("div").text());
});
});
</script>
</head>
<body>
<div>
<h1 id="h1">This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<p>This is another paragraph.</p>
<p>This is another paragraph.</p>
</div>
<button id="default">default</button>
</body>
</html>
result:
最初のalert出力
This is a heading
This is a paragraph.
This is another paragraph.
This is another paragraph.
This is another paragraph.
2番目のalert出力
This is a heading
This is a paragraph.
This is another paragraph.
This is another paragraph.
This is another paragraph.