简体   繁体   English

如何使用Tritium删除html中的空格

[英]How to remove white space in html using Tritium

I'm using the Moovweb SDK and I'd like to remove excess white space from the beginning or end of any elements. 我正在使用Moovweb SDK ,我想从任何元素的开头或结尾删除多余的空格。 It sometimes shows up as or and I want to remove it since it messes with my spacing. 它有时会显示为或者我想删除它,因为它与我的间距混淆。 How can I get around doing this? 我怎么能这样做呢?
Thanks. 谢谢。

You can use regex to replace the leading and tailing whitespace with nothing. 您可以使用正则表达式来替换前导和拖尾空格。

Inside a tag, you can open up a text scope and use the replace(...) function to replace leading and trailing whitespace: 在标记内部,您可以打开文本范围并使用replace(...)函数替换前导和尾随空格:

text() {
    replace(/^\s+|\s+$/, "")
}

Here's a working example in play.tritium.io: 这是play.tritium.io中的一个工作示例:

http://play.tritium.io/648c6b2f72266b7b7db308e14dcb85f71707f4ee http://play.tritium.io/648c6b2f72266b7b7db308e14dcb85f71707f4ee

text("   I'm an example             ")
text() {
  trim()
}

can also be used to remove white spaces 也可以用来删除空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM