简体   繁体   English

字符串处理的快速问题

[英]Quick question to string handling

I'm pretty new to JavaScript, so I hope you could help me. 我对JavaScript非常陌生,所以希望您能对我有所帮助。

I have a top navigation menu with text on image buttons. 我有一个顶部导航菜单,图像按钮上有文字。 When the text is just one word everything is fine. 当文本只是一个单词时,一切都很好。 When it consists of two words I want to cut the string on the space character and put the second word into the second line. 当它由两个单词组成时,我想在空格字符上剪切字符串,然后将第二个单词放入第二行。

I know I can find the character with the indexof method. 我知道我可以使用indexof方法找到字符。 But how would I go from there? 但是我怎么去那里呢?

Thanks 谢谢

' '替换为'<br>'

s = s.replace(/ /g, '<br>')

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

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