查找<iframe>宽度和高度

我有一个这样的对象:

object = {
    iframe: "<iframe width="560" height="315" src="YouTube link"></iframe>"
}

我需要使用jQuery / js在其中获取宽度(在这种情况下为560)和高度(在这种情况下为315)的值。因为我需要使用此值。

那可能吗?

谢谢。

柠檬狗

您可以使用regex隔离两个参数:

var object = {
    iframe: '<iframe width="560" height="315" src="YouTube link"></iframe>' // string was invalid before, replaced quotes with apostrophes
}
var regexFound = object.iframe.match(/width="(\d*?)" height="(\d*?)"/);
var asArray = [regexFound[1], regexFound[2]];
var asObject = {width: regexFound[1], height: regexFound[2]}
console.log(asArray, asObject);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章