我有看起来像这样的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注入(inject)javascript中?
最佳答案
使用.html
而不是.text
。
$(this).next('a').html('Liquid Handler #:<b>' + userInput + '</b>');