3

jQuery を使用してテキスト文字列を解析し、そこから変数を作成しようとしています。文字列は以下のとおりです。

Publications Deadlines:   armadllo

私はすべてを「Publications Deadlines:」を過ぎて取得しようとしているので、長さや単語数に関係なく、名前が何であれ含まれます。

次のように、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 に答える