JavaScript函数的基础应用

函数的引入示例:使div变大变绿。代码如下:

document.getElementById('div1').style.height = '200px';
document.getElementById('div1').style.width = '200px';
document.getElementById('div1').style.background = 'green';

函数的概念:函数是可复用的代码块。以下是定义和使用函数的示例:

function changeDivAppearance() {
  var d1 = document.getElementById('div1');
  d1.style.height = '200px';
  d1.style.width = '200px';
  d1.style.background = 'green';
}

在JavaScript中,通过function关键字定义函数,并通过调用函数来执行其中的代码。

ppt 文件大小:1013.5KB