我在以编程方式插入编辑器中的标记时遇到问题。我不知道如何添加 target="_blank"属性。即使我尝试了“”“”或“”“”以及各种组合,我也无法让它工作。我也不知道这个任务叫什么,所以我无法真正用谷歌搜索它。 任何帮助我们完成这项工作将不胜感激
var html = "<a href='" + host + "/draught/connect/Download" + draughtDownloadType + "?PropId=" + selectedPropertyId + autoUpdateQuery + "' target=_blank>" + linkText + "</a>";
最佳答案
您需要通过在其前面放置 \
来转义 "
字符。
target=\"_blank\"
给你:
var html = "<a href='" + host + "/draught/connect/Download" + draughtDownloadType + "?PropId=" + selectedPropertyId + autoUpdateQuery + "' target=\"_blank\">" + linkText + "</a>";
关于带a标签的javascript变量(字符串构建),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43850160/