换行符不适用于Javascript [英] \n newline character won't work with Javascript

查看:62
本文介绍了换行符不适用于Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在不同的行中放置不同的信息,我有一个工作的Javascript库,但我不能强制文本输出显示换行符。以下是Javascript的相关部分:

I need to put different information in separate lines, I have a working Javascript library, but I can't force the text output to display a newline. Here is the relevant part of the Javascript:

var information = layer.objectAdd({
            type:"tooltip", 
            clickable: true,
            Title: "My title", 
            Description: "My description1 \nMy description2"});

这是所需的输出:

My description1
My description2

这是什么我得到:

My description1 My description2

为什么会这样,我的意思是还有另一种跳转到换行符的方法吗?

Why is this, I mean is there another way to jump to a newline?

抱歉,如果我想错了某人,我有一个用于生成工具提示的Javascript库。我无法改变它,因为这不是我的决定。我需要让它工作,我不能使用任何HTML标签,因为我会打印出来,因为它没有用HTML呈现。就像,我刚试过

Sorry if I missled someone, I have a Javascript library for generating tooltips. I cannot change it because it's not my decision to make. I need to make it work, and I can't use any HTML tags because I will get it printed out because it's not being rendered in HTML. Like, I just tried

Description: "My description1 <br /> My description2"});

它刚打印我的描述1< br />我的描述2 。相同的旧,相同的旧。

And it just printed My description1 <br /> My description2. Same old, same old.

更新:我无法控制它是如何显示的,我只是填写可用的属性比如点击能力,标题,描述等。我试着在描述中添加HTML,但无论你编写什么代码,它都只是输出所有字符串。

UPDATE: I have no control over it how is it displayed, I'm just filling in the available properties such as click able, Title, Description etc. And I've tried to add HTML inside Description, but it just outputs everything as a string no matter what code you write.

推荐答案

您正在使用您不允许/无法编辑的专有JavaScript库。您还不允许/能够向我们展示其渲染功能的源代码,或者自己阅读它以弄清楚它是如何逃避数据的。最后,你不能/不会给我们这个库的名称(假设它是公开的)所以我们可以自己研究它。

You're using a proprietary JavaScript library that you're not allowed/able to edit. You're further not allowed/able to show us the source code of its render function or read it yourself to figure out how it escapes data. Finally, you can't/won't give us the name of this library (assuming it's publicly available) so we can research it ourselves.

你似乎已经尝试过有人可以假设这种方式的唯一合理方式是可行的。

You appear to have tried the only reasonable ways that somebody could assume this would work.

唯一可行的解​​决方案是联系您的供应商并要求回答。

The only possible solution is to contact your vendor and demand an answer.

这篇关于换行符不适用于Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆