好长时间没有写学习笔记了,也不知道天天在忙什么,学习还是要继续,笔记也是要记录,本套javascript教程是根据官方w3c网学习的。
javascript可以改变页面内容
<!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>
</head>
<body>
#改变页面内容
<h2>what can javascript do?</h2>
<p id = "demo">javascript can change html content</p>
<button type="button" onclick="document.getElementById('demo').innerHTML='hellow javascript'"> come on ,chilc me!</button>
</body>
</html>
javascript可以设置字体大小
<!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>
</head>
<body>
#设置字体大小
<h2>what javascript can do?</h2>
<p id='demo'>javascript can change html stype of html element!</p>
<button type="button" onclick="document.getElementById('demo').style.fontSize='35px'"> chick me</button>
</body>
</html>
隐藏元素
<!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>
</head>
<body>
#隐藏元素
<h2>what javascript can do!</h2>
<p id = 'demo'>javascript can hide element!</p>
<button type="button" onclick="document.getElementById('demo').style.display='none'">clice me</button>
</body>
</html>
脚本放到head标签中
<!DOCTYPE html>
<html lang="en">
<head>
#javascript的脚本放在<head>标签中
<script>
function myfunction(){
document.getElementById('demo').innerHTML="范存军!"
}
</script>
<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>
</head>
<body>
<h1>a web page!</h1>
<p id= 'demo' >a paragrap changed</p>
<button type="button" onclick="myfunction()"> tyr it </button>
</body>
</html>
显示隐藏的元素
<!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>
</head>
<body>
#点击菜单显示隐藏的元素
<h2>what can javascript do?</h2>
<p id='demo' style="display:none">hellow world!</p>
<button type="button" onclick="document.getElementById('demo').style.display='block'">come on ,click me!</button>
</body>
</html>
网友评论