2016-12-11 11 views
0

私は現在、ボタンをクリックするとJavaScriptを使ってHTML タグを使用して別のウェブページのフレームを表示するコードを作成しています。以下はjQuery text()関数を使用してウェブページにHTMLタグを追加する

私はウェブページに表示するために使用したコードです:

<html> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script> 
     $("p").text('<iframe src="webpage.html" width="450" height="475" style="overflow:hidden"></iframe>'); 
    </script> 
    <p></p> 
</html> 

結果:
<iframe src="webpage.html" width="450" height="475" style="overflow:hidden"></iframe>

は、悲しいことに、それは単に、実際にフレームを取得せずにテキストを出力します。どのようにテキストを出力しているか、間違った関数を使っていますか?私は( '...')引用を削除... を試してみましたタグが生じ

周り

... Webページがで役に立たない

答えて

1

使用HTMLであることテキストの代わり...

<html> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script> 
     $("p").html('<iframe src="webpage.html" width="450" height="475" style="overflow:hidden"></iframe>'); 
    </script> 
    <p></p> 
</html> 
+0

簡単な修正、お返事ありがとうございます! – EDCisBack

+0

あなたは心から歓迎しています...そして最高の答えとしてお選びください.. –

+0

楽しむことができます....... –

0

そのテキストとHTMLを用心は異なる機能を持っています

Text() : it replaces the text inside the html div or class specified but 
       but not the html 

    html() : it replaces the specified dom of html div/class ,or to be more specific 
      the function called returns or set the content (returning an innerHtml), 
      when you use to return content, it return the first matches, 
      if not it overwrites the content of all matched elements. 
関連する問題