[英]how to include html inside of javascript
我有javascript jquery看起來像這樣:
var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + userInput);
我想知道如何將html包含在文本中,如下所示:
var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + '<b>' + userInput + </b>);
我如何將html注入javascript?
使用.html
而不是.text
。
$(this).next('a').html('Liquid Handler #:<b>' + userInput + '</b>');
jQuery的.html()方法應該有所幫助。
您可以將.text
更改為.html
但請記住,從長遠來看,這很容易出現問題,因為您將不得不逃避任何通過它的事情。 更好的方法可能是做這樣的事情:
$(this).next('a').text('Liquid Handler #:').append($("<b>").text(userInput));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.