我试图将一个包含 html 和非 html 的字符串分成两个字符串。
我的 JavaScript 字符串是:
<span>1x</span> Front-line zero tolerance productivity
我希望将其分为两个变量
var quantity = "1x";
var name = "Front-line zero tolerance productivity";
最佳答案
当 <span>
时分割或</span>
找到标签。
string = "<span>1x</span> Front-line zero tolerance productivity"
tokens = string.split(/<\/?span>/); // returns ["", "1x", " Front-line zero tolerance productivity"]
var quantity = tokens[1] // "1x"
var name = tokens[2]; // "Front-line zero tolerance productivity"
关于javascript - 将带有html的字符串分成两个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11005464/