编程语言经常依赖键/值对。函数有名字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 发布
本文介绍了一个简单的JavaScript函数updateMessage,该函数用于更新网页上的消息内容。通过修改特定元素的textContent属性,可以轻松实现消息的动态展示。示例代码展示了如何在HTML页面中使用此函数来更改欢迎消息。
7743

被折叠的 条评论
为什么被折叠?



