HTML 替换型元素

2019-11-20  本文已影响0人  欢欣的膜笛

替换型元素

script

// 替换型标签
<script type="text/javascript" src="my.js"></script>

// 不作为替换型标签
<script type="text/javascript">
    console.log("Hello world!");
</script>

img

// srcset 提供了根据屏幕条件选取图片的能力,但是其实更好的做法,是使用 picture 元素
<img srcset="elva-fairy-320w.jpg 320w, 
             elva-fairy-480w.jpg 480w, 
             elva-fairy-800w.jpg 800w"
     sizes="(max-width: 320px) 280px, 
            (max-width: 480px) 440px,
            800px"
     src="elva-fairy-800w.jpg" alt="Elva dressed as a fairy">

picture

<picture>
    <source srcset="image-wide1.png" media="(min-width: 600px)">
    <source srcset="image-wide2.png" media="(min-width: 900px)">
    <img src="image-narrow.png">
</picture>

video

<video controls="controls" src="movie.ogg"></video>

<video controls="controls" >
    <source src="movie.webm" type="video/webm" >
    <source src="movie.ogg" type="video/ogg" >
    <source src="movie.mp4" type="video/mp4">
    <track kind="subtitles" src="subs_chi.srt" srclang="zh" label="Chinese">
    <track kind="subtitles" src="subs_eng.srt" srclang="en" label="English">
    You browser does not support video.
</video>

audio

<audio controls>
    <source src="song.mp3" type="audio/mpeg">
    <source src="song.ogg" type="audio/ogg">
    <p>You browser does not support audio.</p>
</audio>

iframe

<iframe src="http://time.geekbang.org"></iframe>
属性 描述
align left / right / top / middle / bottom 不赞成使用,请使用样式代替。规定如何根据周围的元素来对齐此框架
width / height pixels / % 规定 iframe 的宽度 / 高度
frameborder 1/ 0 规定是否显示框架周围的边框
marginwidth / marginheight pixels 定义 iframe 的四周的边距
scrolling yes / no / auto 规定是否在 iframe 中显示滚动条
name string 规定 iframe 的名称
src string 规定在 iframe 中显示的文档的 URL
longdesc string 规定一个页面,该页面包含了有关 iframe 的较长描述
sandbox "" / allow-forms / allow-same-origin / allow-scripts / allow-top-navigation 启用一系列对 <iframe> 中内容的额外限制
srcdoc HTML_code 规定在 <iframe> 中显示的页面的 HTML 内容
/* 
使用 srcdoc 属性创建了一个新的文档,嵌入在 iframe 中展示,
并且使用了 sandbox 来隔离,这样,这个 iframe 就不涉及任何跨域问题了
*/
<iframe sandbox srcdoc="<p>Hello world!</p>" src="demo-iframe_srcdoc.html">
    <p>您的浏览器不支持 iframe 标签。</p>
</iframe>
// iframe1:页面中的iframe的ID;
// news_text:iframe内需要被操作的元素的ID;

$("#iframe1").contents().find("#news_text").html("");

document.getElementById('iframe1').contentWindow.document.getElementById('news_text').style.color='red'
上一篇 下一篇

猜你喜欢

热点阅读