前端_day08_JavaScript

JavaScript

一.输出

  1.在浏览器的控制台输出:console.log("要输出的内容")

  2.直接输出在页面中:document.write("要输出的内容")

二.函数

  1.语法:function 方法名(参数列表){方法体}

  2.js可以有返回值,也可以没有返回值,返回值为任意类型

  3.调用函数式,传入的参数可以与函数参数列表中参数个数不同,如果传的参数多,多余的则会被舍弃,如果传的参数少,那么未给定的参数是undefined类型

  4.方法中定义变量如果没有写var那么直接定义的是全局变量,可以在直接其他方法中使用

二.提示框

  1.允许输入内容的提示框:

    var content = prompt('提示内容')

    document.write(content)

  2.确定/取消提示框:

    var flag = confirm('确认删除?')

  3.确认提示框:

    alert('成功')

三.时间对象,示例代码:

  <script type="text/javascript"> 

    var date = new Date()

    document.write(date)

  </script> 

四.焦点对象,示例代码:

  <script type="text/javascript">  

    var userInput = document.getElementById('username')

    userInput.onfocus = function () {   //获取焦点

      userInput.style.backgroundColor = '#f00'}

    userInput.onblur = function () {  //失去焦点
      userInput.style.backgroundColor = '#0f0'}

  </script>

五.点击事件

  <button id="btn_1" onclick="fun1()">click me</button> //单击
  <input type="submit" onclick="fun1()">
  <input type="button" id="double" value="double click"> //双击
  <script type="text/javascript">
    function fun1() {
      alert("You have clicked")}
    var doubleInput = document.getElementById("double")  //获取js对象
    doubleInput.ondblclick=function () {
      alert('666')}
  </script>

 

 

猜你喜欢

转载自www.cnblogs.com/memo-song/p/9102159.html