如何在javascript中包含html

如何在javascript中包含html,javascript,jquery,html,Javascript,Jquery,Html,我的javascript jquery如下所示: var userInput = prompt("Liquid Handler #:", "Liquid Handler #:"); $(this).next('a').text('Liquid Handler #:' + userInput); var userInput = prompt("Liquid Handler #:", "Liquid Handler #:"); $(this).next('a').text('Liquid Hand

我的javascript jquery如下所示:

var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + userInput);
var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + '<b>' + userInput + </b>);
$(this).next('a').text('Liquid Handler #:').append($("<b>").text(userInput));
我想知道如何将html包含到文本中,如下所示:

var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + userInput);
var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + '<b>' + userInput + </b>);
$(this).next('a').text('Liquid Handler #:').append($("<b>").text(userInput));
var userInput=prompt(“液体处理程序:”,“液体处理程序:”;
$(this).next('a').text('Liquid Handler#):'+''+userInput+;

如何将html注入javascript?

使用
.html
而不是
.text

$(this).next('a').html('Liquid Handler #:<b>' + userInput + '</b>');
$(this.next('a').html('Liquid Handler#:'+userInput+');

jQuery的方法应该会有所帮助。

您可以将
.text
更改为
.html
,但请记住,从长远来看,这很容易出现问题,因为您将不得不逃避任何经过它的操作。更好的方法可能是这样做:

var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + userInput);
var userInput = prompt("Liquid Handler #:", "Liquid Handler #:");
$(this).next('a').text('Liquid Handler #:' + '<b>' + userInput + </b>);
$(this).next('a').text('Liquid Handler #:').append($("<b>").text(userInput));
$(this.next('a').text('Liquid Handler#::')。append($(“”)。text(userInput));

您是否尝试将
文本()
更改为
html()
?您的
没有用单引号括起来。。。