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 是字符串中唯一包含在单引号中的部分,则可以将字符串拆分为包含 [ before text ,*text in quotes*, after text ] 的数组:

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 回答