Javascript 如何从iframe标记中删除样式(不是在iframe内部,而是在标记内部)
我服务器上的页面有多个ID不同的iframe标记。我添加了一个iframe标记以嵌入youtube视频。iframe标记有一个样式元素,该元素提供250宽和250高,由插件添加。我想删除添加到iframe中的此样式,以便youtube视频在iframe标记中显示此特定iframe的高度和宽度,因为页面上还有其他iframe标记具有不应触摸的样式 1) 我正在添加的代码(注意宽度=640高度=390) Javascript或Jquery会很好。但是jquery中的remove标记会从页面上的每个iframe中剥离样式 理想的解决方案将导致只有带有Javascript 如何从iframe标记中删除样式(不是在iframe内部,而是在标记内部),javascript,jquery,iframe,Javascript,Jquery,Iframe,我服务器上的页面有多个ID不同的iframe标记。我添加了一个iframe标记以嵌入youtube视频。iframe标记有一个样式元素,该元素提供250宽和250高,由插件添加。我想删除添加到iframe中的此样式,以便youtube视频在iframe标记中显示此特定iframe的高度和宽度,因为页面上还有其他iframe标记具有不应触摸的样式 1) 我正在添加的代码(注意宽度=640高度=390) Javascript或Jquery会很好。但是jquery中的remove标记会从页面上的每个i
id=“player”
的iframe从上面的2)更改为不再具有style=“”
或具有style=“”,但其中没有任何内容
$('#player').removeAttr('style')
应该可以使用最新的jQuery
作为解释
$('#player')
以id='player'作为DOM元素的目标(#以id为目标,如css选择器)
从目标对象中删除“样式”属性
Try with ,
For style change :
$("#player").css("Height","90");
For attribute change :
$("#player").attr("Height","90");
For inside of iframe tag attribute or style change :
$("#player div").attr("Height","90");
$("#player div").css("Height","90");
应该可以使用最新的jQuery
作为解释
$('#player')
以id='player'作为DOM元素的目标(#以id为目标,如css选择器)
从目标对象中删除“样式”属性
Try with ,
For style change :
$("#player").css("Height","90");
For attribute change :
$("#player").attr("Height","90");
For inside of iframe tag attribute or style change :
$("#player div").attr("Height","90");
$("#player div").css("Height","90");
$('#player').removeAttr('style');
试试这个
$('#player').removeAttr('style');
document.getElementById('player')。removeAttribute('style')
我认为您不应该使用jQuery或任何其他JS库
CSS解决方案:
#播放器{宽度:640px!重要;高度:390px!重要;}
但使用!重要提示
是不好的做法。document.getElementById('player')。removeAttribute('style')
我认为您不应该使用jQuery或任何其他JS库
CSS解决方案:
#播放器{宽度:640px!重要;高度:390px!重要;}
但使用!重要提示
是不好的做法。@DocKuro。。。速度更快,没看到。我也经常这样:)@DocKuro。。。我也经常这样:)这是不好的做法,但它完全有效:)这是不好的做法,但它完全有效:)