Javascript删除空白时不应该? [英] Javascript Removing Whitespace When It Shouldn't?

查看:153
本文介绍了Javascript删除空白时不应该?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML文件,其代码类似于以下内容。

I have a HTML file that has code similar to the following.

<table>
    <tr>
    <td id="MyCell">Hello  World</td>
    </tr>
</table>

我正在使用像下面这样的javascript来获取值

I am using javascript like the following to get the value

document.getElementById(cell2.Element.id).innerText

这将返回文本Hello World,在hello和world之间只有1个空格。我必须保持相同数量的空格,有没有办法完成?

This returns the text "Hello World" with only 1 space between hello and world. I MUST keep the same number of spaces, is there any way for that to be done?

我尝试使用innerHTML,outerHTML和类似的项目,但我是没有运气。

I've tried using innerHTML, outerHTML and similar items, but I'm having no luck.

推荐答案

HTML是白色空间不敏感,这意味着你的DOM也是。将 pre 块中的Hello World包裹起来吗?

HTML is white space insensititive which means your DOM is too. Would wrapping your "Hello World" in pre block work at all?

这篇关于Javascript删除空白时不应该?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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