Eclipse在多行上键入代码

时间:2013-04-10 16:34:48

标签: javascript eclipse text lines

当我尝试在javascript中输入文本(在“”之间)时,我必须在1行上写下所有内容。 我无法按Enter键,因为我的代码无效。

显然你不能在javascript中输入多行。 这是正确的还是我犯了错误?

示例:

var htmlcode = "<strong>29 juni 2013</strong> <br/> 22u";
//This works

var htmlcode = "<strong>29 juni 2013</strong> 
<br/> 
22u";
//This doesn't work

2 个答案:

答案 0 :(得分:3)

如果您希望将代码分解为多行,您可以执行以下任一操作:

// Concatenate to the string
var htmlcode = "<strong>29 juni 2013</strong> "
    + "<br/> "
    + "22u";

// Use backslashes at the end of each line. May not be supported everywhere,
//   so I'd avoid this approach.
var htmlcode = "<strong>29 juni 2013</strong> \
<br/> \
22u";

答案 1 :(得分:1)

在Eclipse内部,有一个选项可以提供帮助。转到首选项 - &gt; JavaScript - &gt;编辑 - &gt;打字。在页面上,启用“自动换行”和“转义文本...”。这将确保如果您在字符串内部按Enter键,则会正确添加引号,\ n和+。