zoukankan      html  css  js  c++  java
  • 在HTML网页中嵌入脚本的方式

      javascript脚本可以出现在html页面的任何地方。需要注意的是javascript在框架页中出现必须在<frameset>标签之前,否则不能运行。

      在html页面中嵌入脚本的方式主要有:

      (1)在html标签的事件属性中直接添加脚本   

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html"; charset="UTF-8">
    <title>在标签的事件属性中直接添加脚本</title>
    </head>
    <body>
      <form>
        <input type="button" value="save" onclick="alert('clicked!');" />
      </form>
    </body>
    </html>

      (2)使用script标签插入脚本

      这种方式是首先将<script>标记插入到html页面的某个地方,然后在<script>标记对之间根据需要编写相关的javascript脚本。一般将<script>标记写在<head></head>之间或者<body></body>之间。

    <head>
    <meta http-equiv="Content-Type" content="text/html"; charset="UTF-8">
    <title>使用script标记插入脚本</title>
      <script type="text/javascript">
      var a=100;
      var b=200;
      if(a<b){
        alert("true");
      }
    </script>
    </head>

      (3)使用script标签链接外部脚本 

      为了重用javascript代码,在实际的开发中,通常将javascript代码编写为一个独立的以js为扩展名的脚本文件。此后u,这个文件中的脚本就可以在不同的html页面中使用。

    html>
    <head>
    <meta http-equiv="Content-Type" content="text/html"; charset="UTF-8">
    <title>使用script标记链接脚本文件</title>
     <script type="text/javascript" src="new_file.js"></script>
    </head>
    <body>
      <form>
        <input type="button" value="save" onclick="clickFunction();" />
      </form>
    </body>
    </html>

  • 相关阅读:
    06列表的常用基本操作
    05字符串的常用基本操作
    什么是全量表,增量表,快照表,拉链表,维度表,事实表,实体表
    什么是拉链表
    数仓设计
    pandas学习
    矩阵和数组的区别
    中文文本关键词抽取的三种方法(TF-IDF、TextRank、word2vec)
    python使用结巴分词(jieba)创建自己的词典/词库
    scrapy是广度优先还是深度优先?
  • 原文地址:https://www.cnblogs.com/jacinthcc/p/4692965.html
Copyright © 2011-2022 走看看