gpt4 book ai didi

javascript - 使用 javascript 将 href 文本分成多行

转载 作者:行者123 更新时间:2023-11-30 12:02:39 24 4
gpt4 key购买 nike

我想将存储在变量“输出”中的超链接文本分成多行。我目前有这个:

var output = "";
output = output.concat("line 1");
output = output.concat("<br />");
output = output.concat("line 2");
output = output.concat("<br />");
var a = document.createElement('a');
var linkText = document.createTextNode(output);
a.appendChild(linkText);
a.title = output;
a.href = "http://www.google.com";

不幸的是,出现了 break 标签的文本,而这些行实际上并没有中断。我也试过用“\n”代替 break 标签,但没有用。有什么建议吗?谢谢!

最佳答案

只需将 a.innerHTML = output 替换为

var linkText = document.createTextNode(output);
a.appendChild(linkText);

更正版本:

var output = "";
output = output.concat("line 1");
output = output.concat("<br />");
output = output.concat("line 2");
output = output.concat("<br />");
var a = document.createElement('a');
a.innerHTML = output;
a.title = output;
a.href = "http://www.google.com";
document.body.appendChild(a);

关于javascript - 使用 javascript 将 href 文本分成多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36241956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com