编程语言经常依赖键/值对。函数有名字updateMessage,其值即代码段(由语句组成)。当通过函数名调用函数时,这些语句就会执行。
<!DOCTYPE html>
<html>
<head>
<title>Basic Function</title>
<link rel="stylesheet" href="css/c03.css" />
</head>
<body>
<h1>TravelWorthy</h1>
<div id="message">Welcome to our site!</div>
<script type="text/javascript">
var msg = 'Sign up to receive our newsletter for 10% off!';
function updateMessage(){
var el = document.getElementById('message');
el.textContent = msg
}
updateMessage();
</script>
</body>
</html>
JavaScript 函数
最新推荐文章于 2022-03-16 01:45:10 发布