'/' 字符保留用于定位文件夹。如果您使用查询会更好。
正则表达式对查询很有用。
//where frame is the iframe you showed above:
var query = JSON.parse(('{'+(frame.source.substr(1).replace(new RegExp("([^=]+)=([^&]+)&?",'g'),function(){return '"'+arguments[1]+'":"'+arguments[2]+'",';}))+'}').replace(/,\}/,"}"));
无论如何,我想您也可以将正则表达式用于您想要的格式。我只是强烈建议您使用查询字符串。
var width = -1;
var height = -1;
...
//frame is the iframe that you show.
//You should consider adding an id attribute to that so that you can identify it later.
//It's good coding practice.
var results = frame.match(/([0-9]+)\/([0-9]+)$/);
if(results.length == 3)
{
width=parseInt(results[1]);
height=parseInt(results[2]);
}
else
{
//something went wrong...
}
如果要更改帧大小,只需调用replace()
而不是match()
. 确保按照EcmaScript 标准中的描述传递函数。
要了解有关 JavaScript 中正则表达式的更多信息,请参阅此网页