【发布时间】:2017-12-04 02:42:49
【问题描述】:
您好,我有一个类似
的 HTML 字符串" <div> <p>You have received an alert from project <span class="fields" field="template.variable.ProjectName"> Project Name</span> <br /> </p> <p> <span field="template.variable.AlertName" class="fields">Alert Name</span> <span field="template.variable.AlertName" class="fields">Alert Name</span> <span field="template.variable.AlertName" class="fields">Alert Name</span> <br /> </p> <p>Follow these steps to access the alert:</p> <ol> <li>Log into your for Contract Management project at <span field="template.variable.AlertProjectLink" class="fields">Alert Project Link</span></li> <li>If necessary, enter your email address and the password that you created when you completed your registration.</li> <li>Go to the Alerts tab to see your unread alerts and access links to the documents.</li> </ol> <p> <span class="fields" field="template.variable.AlertDocumentList"> Alert Document List</span></p> <p>Please do not reply to this message</p> <p>.Space2 space gaurav Replies are routed to an unmonitored mailbox.</p> <p>If you would like additional assistance, please contact Merrill Technical Support, available 24 hours a day, seven days a week.</p> <p> <span class="template" field="template.variable.ImportTemplate" template="template.types.TechSupportContactInformation"> Tech Support Contact Information</span> test</p> <p>Testing is going on</p> </div> "
我需要用单个空格而不是标签内的所有连续空格替换,就像你可以看到我有<span field ="template.variable.AlertName" class="fields"> Alert Name</span>
我需要<span field="template.variable.AlertName" class="fields">Alert Name</span>
如你所见,我不想触及 HTML 标签属性的空格。
任何帮助将不胜感激。
*仅限JAVASCRIPT
【问题讨论】:
-
使用 trim() - w3schools.com/jsref/jsref_trim_string.asp
-
@BalajMarius 不起作用
-
一个或多个空格和换行符在 HTML 中被解释为一个空格,那么有什么意义呢?
-
仅供参考,如果您删除 pre 标签之间的空格,您将被破坏。
标签: javascript string replace space