jQuery Remove string from string

后端 未结 5 1785
情书的邮戳
情书的邮戳 2021-01-31 00:59

I am trying to remove a string from a string in jQuery.

Here is the string:

username1, username2 and username3 like this post.

I would

5条回答
  •  暖寄归人
    2021-01-31 01:59

    I assume that the text "username1" is just a placeholder for what will eventually be an actual username. Assuming that,

    • If the username is not allowed to have spaces, then just search for everything before the first space or comma (thus finding both "u1 likes this" and "u1, u2, and u3 like this").
    • If it is allowed to have a space, it would probably be easier to wrap each username in it's own span tag server-side, before sending it to the client, and then just working with the span tags.

提交回复
热议问题