【html】link,script

    xiaoxiao2021-03-26  27

    1.  link 标签

    功能:指定了 当前文档 和 链接的外部资源的关系,通常用于 链接一个外部样式表(css 文件);

    语法:只能定义在 html 的  head 标签内,且可以出现多次; html 中

    <link [属性]/> // 这里的属性为 html 的 全局属性;

    栗子:html 中链接一个外部样式表(css 文件)

    <link rel="stylesheet" type="text/css" href="custom.css"/> 常用属性:

            rel:决定外部资源 和 当前文档的关系 (relation),链接外部样式表时的值为  stylesheet

            type:规定被链接 的 外部资源的 MIME 类型,例如 text/css ,text/html,链接外部样式表时值为 text/css:表示 层叠样式表 (Cascading Style Sheet)的形式;

            href:指定被链接资源的 URL;(Hypertext Reference)

    2. script 标签

    功能:用于 嵌入 或 引用 一个可执行的脚本;

    语法:

    <script [属性]>[ js code]</script>

    嵌入一个可执行脚本栗子:

    <script type="text/javascript"> document.write("Hello World!") </script> 引用一个可执行脚本栗子:

    <script type="text/javascript" src="custom.js"></script> 常用属性:

         type:必须属性,指定 MIME 类型,此时为 text/javascript;

         src :可选属性,指定引用脚本的 URL;

         async:异步执行此脚本;html5 支持的语法;

       

    另外,script 可以 通过js 获取 和 创建;

    可执行脚本的编写:

    window.onload   VS    $(document).ready(handler)

    window.onload = funcRef 

    funcRef 是 指 window 的加载事件 触发时 调用的 处理函数;

    触发时间是 在 文档加载过程结束时;此时,所有的图片,script 脚本,link 链接资源 以及子框架都已经完成加载;

    栗子:

    window.onload = function() { init(); doSomething(); }; $(document).ready(handler)

    .ready(handler)属于 jquery 的一个方法,详情参看  .ready()

    指定了一个处理函数,该函数在 DOM (Document Object Model)完全 加载后执行;几种使用方法:

         $(handler):                                                   推荐使用

         $(document).ready(handler):

         $("document").ready(handler);

         $("img").ready(handler):

         $().ready(handler):

    栗子:

    $(function() { init(); doSomething(); });

    转载请注明原文地址: https://ju.6miu.com/read-663719.html

    最新回复(0)