1

私は文字列として変数にこのコードの束を持っています:

.... = 40; var posY = 40; MAX_727.moveTo(posX, posY); } MAX_727.location='http://one.cam4ads.com/www/delivery/ac.php?bannerid=727&zoneid=19&target=_blank&withtext=0&source=&timeout=0&ct0='; MAX_727.blur(); window.focus...

(読みやすくするために、最初と最後にドットを追加しました)

このコード(文字列として操作されている)には、変数値、が含まれていますMAX_727.location

その特定の変数の値を抽出するにはどうすればよいですか?

4

2 に答える 2

1

正規表現を使用できます:

var value = /MAX_727\.location=\'([^\']*)/.exec(s)[1];

デモンストレーション

于 2012-11-16T19:38:11.450 に答える
0

MAX_727.locationが文字列の中で一重引用符で囲まれている唯一の部分である場合、文字列を[テキストの前、*引用符で囲まれたテキスト*、テキストの後]を含む配列に分割できます。

var codeString = "your String goes here";
var codeArray = codeString.split("'"); //Split the String at every ' mark, and add it to an array
var location = codeArray[1]; //Get the second value in the array, or the part of the String that was in quotes.
于 2012-11-16T19:42:56.193 に答える