首页 文章

如何从iframe标记中删除样式(不在iframe内部,但在标记内)

提问于
浏览
0

我服务器上的页面有多个具有不同ID的iframe标记 . 我添加了一个iframe标记来嵌入YouTube视频 . iframe标签有一个样式元素,可以通过插件添加250宽度和250高度 . 我想删除添加到iframe的此样式,以便youtube视频在iframe标记的高度和宽度中仅显示此特定iframe,因为页面上的其他iframe标记具有不应触及的样式 .

1)我添加的代码(通知宽度= 640高度= 390)

<iframe id="player" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/GxTl1Ykbuww?enablejsapi=1&origin=origin-domain.com" frameborder="0"></iframe>

2)加载浏览器时在页面上的代码(注意 style="height:250;width:250;" 现在被添加到iframe标签,这是我想要删除的垃圾,但仅来自此iframe标签ID

<iframe id="player" style="height: 250px; width: 250px;" src="http://www.youtube.com/embed/GxTl1Ykbuww?enablejsapi=1&amp;origin=origin-domain.com" height="390" width="640" frameborder="0"></iframe>

Javascript或Jquery会很好 . 但jquery中的remove标记从页面上的每个iframe中剥离样式 .

理想的解决方案只会导致iframe与 id="player" 从2)更改为不再具有 style="" 或者具有style =“”但其中没有任何内容 .

4 回答

  • 0
    $('#player').removeAttr('style')
    

    应该使用最新的jQuery

    作为解释

    $('#player')
    

    目标是一个id ='player'的DOM元素(#target id,就像css选择器一样) .

    removeAttr('style')
    

    从目标对象中删除'style'属性

  • 1

    document.getElementById('player').removeAttribute('style')

    我认为不应该使用jQuery或任何其他JS库

    CSS解决方案: #player { width: 640px !important; height: 390px !important; } 但使用 !important 是不好的做法 .

  • 2

    试试这个

    $('#player').removeAttr('style');
    
  • 0
    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");
    

相关问题