js:基础方法

  • <!DOCTYPE html>
    <html lang="en">
    
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/demo.js"></script>
    </head>
    
    <body>
    <button type="button" onclick="showInfo()">调用函数</button>
    <button type="button" onclick="disp_confirm()">确认框</button>
    <button type="button" onclick="disp_prompt()">提示框</button>
    <button type="button" onclick="loc()">location跳转页面</button>
    <button type="button" onclick="location.reload()">刷新页面</button>
    </body>
    </html>
    

demo.js

  •  1. // function showInfo() {
     alert("这是一个警告框......")
     }
    
  •  2. //confirm()方法用于显示一个带有指定消息和OK以及取消按钮的对话框。
     function disp_confirm() {
     var r = confirm("Press a button")
     if (r == true) {
      document.write("You pressed OK!")
     } else {
      document.write("You pressed Cancel!")
     }
     }
    
  • 3. //prompt() 方法用于显示可提示用户进行输入的对话框。
    function disp_prompt() {
    var name = prompt("Please enter your name", "");
    if (name != null && name != "") {
      document.write("Hello " + name + "!")
    }
    }
    
  • 4. //Location 对象包含有关当前 URL 的信息。
       //Location 对象是 Window 对象的一个部分,可通过 window.location 属性来访问。//
    function loc() {
    location.href = "http://www.163.com";
    }
    
  • 5. //reload() 方法用于重新加载当前文档
    function reloadPage() {
    location.reload();
    }
    
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.方法 在一个对象中绑定的函数,称为这个对象的方法 2.this的使用 1.在一个 方法 的内部,this是一个...
    梦见君笑阅读 470评论 0 0
  • 1.输出语句:document.write(""); 2.JS中的注释为:// 3.传统的HTML文档顺序是:do...
    续写那未完的记忆阅读 386评论 0 5
  • 一、JS前言 (1)认识JS 也许你已经了解HTML标记(也称为结构),知道了CSS样式(也称为表示),会使用HT...
    凛0_0阅读 2,995评论 0 8
  • 夜色渐渐暗下来,路上的行人逐渐稀少起来,抬头看看手表,已经快七点五十了,离火车开动还有一个半多小时!此刻本刚平静下...
    竹林深处_ef71阅读 340评论 0 3
  • 回到老家,没有电脑的日子,总要找些趣事来消磨时光,kindle就是我的选择啦,所以带着满满的兴致与对村上春树的敬意...
    岛上大多数阅读 347评论 1 0

友情链接更多精彩内容