希望有人能在这里帮助我。 我有一个带有 iframe 的变量,就像这样。
var iframe = '<iframe src="http://someaddress.com" width="600" height="500"></iframe>';
我想从变量中获取 src、宽度和高度,并放入它们自己的变量中。我知道我可以对它使用正则表达式,但我不知道该怎么做。
最佳答案
var iframe = '<iframe src="http://someaddress.com" width="600" height="500"></iframe>',
regEx = /(src|width|height)=["']([^"']*)["']/gi;
iframe.replace(regEx, function(all, type, value) {
console.log(type); // src/width/height
console.log(value); //url/600/500
});
关于javascript - 使用javascript从变量中的iframe获取src宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13380279/