如何在jquery代码中打印html标签

I want to print the audio tag in html what should I add in my html code

<script ></script>
$(document).ready(function() 
{            
  // Request 
  jQuery.getJSON
  (
    ,
    {
      prot_vers: 2, cl_login: " ", cl_app: " ", cl_pwd: " ", 
      req_voice:"heather22k", 
      req_text:$("#demo_voices_textarea").val()
    },
    function(data) 
    {
      //api response management 
      $("#demo1player").html("<audio src='"+data.snd_url+"' controls='controls' />"); 
    }                       
  );
});

and my html code is here

 <form name="Test"  method="post">
<textarea name="demo_voices_textarea" rows="4" cols="20">Hello World !</textarea>
<br/>
<input type="submit" value="Create sound!">
</form>

many thanks

</div>

4个回答

Instead of .html() use .text() as shown :-

$("#demo1player").text("<audio src='"+data.snd_url+"' controls='controls' />");

Use <pre>...</pre> tag

$("#demo1player").html("<pre><audio src='"+data.snd_url+"' controls='controls' /></pre>"); 
dongwu9063
dongwu9063 如果它解决了您的问题,请考虑投票并将其标记为正确答案。
5 年多之前 回复

Use &lt; and &gt; instead < and > :

$("#demo1player").html("&lt;audio src='"+data.snd_url+"' controls='controls' /&gt;");



我会使用$(element).text()函数。 几天前,我已经看过如何在javascript中转义html。 我发现以下链接:使用jQuery转义HTML字符串 </ p>

我认为它应该适用于您的目的。</ p>
</ div>

展开原文

原文

I would use the $(element).text() function. A few days ago I've looked how to escape html in javascript. I found following Link: Escaping HTML strings with jQuery

I think it should work for your purpose.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问