如何在javascript变量的纯文本内添加html标签

时间:2018-07-03 10:25:34

标签: javascript html hyperlink tags anchor

我在javascript代码中具有以下变量,该变量在网站的弹出消息上显示纯文本。

procedure Add_Event_Handler(Self : out Event_Handers; Handler : access Event_Handler) is
        I : Event_Handler_Index := Event_Handler_Index'First; --'
    begin
        while I < Event_Handler_Index'Last loop --'
            if Self(I) = null then
                -- Notice the casting here
                Self(I) := Event_Handler_Generic_Ptr(Handler); -- ======> The error is raised here <======
                exit;
            end if;
            I := I + 1;
        end loop;
    end;

我试图通过向其添加锚标记来使“隐私策略”显示为超链接。我该如何实现?

3 个答案:

答案 0 :(得分:0)

var msg = '<h1>Message</h1>'

要使Web浏览器将其转换为HTML,您需要使用document.write()方法。

答案 1 :(得分:0)

使用elements代替cookieconsent库的content属性。所以用

elements: {
  message: 'This website is using browser cookies as per our internal cookie policy and <a href="/privacy-policy"> privacy policy</a>.'
}

代替

content: {
  message: 'This website is using browser cookies as per our internal cookie policy and <a href="/privacy-policy"> privacy policy</a>.'
}

答案 2 :(得分:0)

从您的问题中我想您正在尝试做这样的事情? 无需将其附加到正文,而是将其附加到弹出窗口,并将href属性更改为所需的内容。

var policy = document.createElement('a');
var t = document.createTextNode('message: This website is using browser cookies as per our internal cookie policy and privacy policy. By entering our website, you acknowledge that you have read and understood our privacy policy');     // Create a text node
policy.appendChild(t);  
policy.setAttribute('href', "http://google.com");
document.body.appendChild(policy);
<html>
<body>

</body>
</html>