我在ASP.CORE View中执行以下JS代码,旨在基本上设置页面上元素的内容。
if (notificationBanner) {
var bannerText = unescape("@ViewData.GetClient().GetText("$.resetCredentials.step2.otpSendBanner")");
console.log(bannerText);
notificationBanner.innerHTML = bannerText;
}
以下内容正在浏览器控制台中登录:
<p>A One Time Password (OTP) has been sent to your mobile number below. Enter the OTP in the field below. <strong>The OTP is valid for 10 minutes</strong>.</p>

元素最终以这种方式结束:
但是这是不正确的,我希望<strong></strong>
中的部分为粗体。为什么将其添加为文本?
我只是在这里提出一个官方解决方案。功劳完全归功于蜡笔小新。一种方法是将文本插入textarea
元素,然后从那里提取文本。它看起来像这样:
if (notificationBanner) {
var bannerText = $('<textarea />').html(unescape("@ViewData.GetClient().GetText("$.resetCredentials.step2.otpSendBanner")")).text();
console.log(bannerText);
notificationBanner.innerHTML = bannerText;
}