3

我正在尝试用 jQuery 解析一个文本字符串并从中创建一个变量。字符串如下:

Publications Deadlines:   armadllo

我试图让所有内容都超过“出版截止日期:”,所以它包括任何名称,无论它有多长或多少字。

我通过 jQuery .text() 函数获取文本,如下所示:

$('.label_im_getting').text()

我觉得这可能是一个我无法组合的简单解决方案。传统的 JS 也可以,如果它比 JQ 更高效!

4

2 回答 2

8

试试这个,

现场演示

第一部分

str = $.trim($('.label_im_getting').text().split(':')[0]);

第二部分

str = $.trim($('.label_im_getting').text().split(':')[1]);
于 2012-10-25T12:09:22.533 回答
4
var string = input.split(':') // splits in two halfs based on the position of ':'
string = input[1] // take the second half
string = string.replace(/ /g, ''); // removes all the spaces.
于 2012-10-25T12:13:58.913 回答