Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用 jQuery 将这个“ - |”变成“ - ”?
.replace(/__-__ | /g, '__-__'
这也替换了空格
.replace('__-__ | ', '__-__'
这仅在第一次发生时替换
不知道你为什么在 jQuery 中尝试这个。字符串替换是一种 javascript 字符串方法,除非您正在谈论替换 DOM 元素。
input.replace(/- \|/g, '-_-');
请参阅此示例。
你的回答对我有帮助!:)
.replace(/__-__ \|/g, '__-__')
这工作得很好!谢谢!