写一个动态网页html
时间: 2023-12-19 17:05:09 浏览: 20
<!DOCTYPE html>
<html>
<head>
<title>动态网页</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#button").click(function(){
$("#text").text("你好,世界!");
});
});
</script>
</head>
<body>
<h1>动态网页</h1>
<button id="button">点击</button>
<p id="text"></p>
</body>
</html>
相关问题
用html写一个动态网页
要用 HTML 写一个动态网页,可以使用 HTML、CSS 和 JavaScript 技术。
HTML 用于网页的结构和内容,CSS 用于网页的样式和布局,JavaScript 用于网页的交互和动态效果。
这是一个简单的例子:
```
<!DOCTYPE html>
<html>
<head>
<style>
button {
padding: 10px 20px;
background-color: green;
color: white;
border: none;
}
</style>
</head>
<body>
<h1>动态网页</h1>
<p>点击按钮更改文字颜色:</p>
<button onclick="document.body.style.color = 'red'">红色</button>
<button onclick="document.body.style.color = 'green'">绿色</button>
<button onclick="document.body.style.color = 'blue'">蓝色</button>
</body>
</html>
```
这是一个简单的动态网页,点击按钮可以更改页面的文字颜色。
希望这个例子能帮助你了解如何用 HTML、CSS 和 JavaScript 写一个动态网页。
用html写一个动态网站
好的,下面是一个简单的动态网站示例,使用 HTML、CSS 和 JavaScript:
```html
<!DOCTYPE html>
<html>
<head>
<title>动态网站示例</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f2f2f2;
}
header {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
font-size: 24px;
font-weight: bold;
}
nav {
background-color: #444;
color: #fff;
padding: 10px;
text-align: center;
font-size: 18px;
font-weight: bold;
}
section {
padding: 20px;
}
article {
background-color: #fff;
padding: 10px;
margin-bottom: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
footer {
background-color: #333;
color: #fff;
padding: 10px;
text-align: center;
font-size: 14px;
}
</style>
</head>
<body>
<header>
<h1>动态网站示例</h1>
</header>
<nav>
<ul>
<li><a href="#" onclick="loadPage('home')">首页</a></li>
<li><a href="#" onclick="loadPage('about')">关于我们</a></li>
<li><a href="#" onclick="loadPage('contact')">联系我们</a></li>
</ul>
</nav>
<section>
<article id="content">
<p>欢迎来到动态网站示例!请选择一个页面。</p>
</article>
</section>
<footer>
<p>© 2021 动态网站示例</p>
</footer>
<script>
function loadPage(page) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("content").innerHTML = this.responseText;
}
};
xhttp.open("GET", page + ".html", true);
xhttp.send();
}
</script>
</body>
</html>
```
这个网站包含了一个标题、导航菜单、内容区域和页脚。导航菜单中有三个链接,点击链接会使用 JavaScript 发送 AJAX 请求加载对应的页面。每个页面都是一个简单的 HTML 文件,包含要显示的内容。
你可以将这些代码保存为一个 HTML 文件并在浏览器中打开以查看效果。注意,由于这个网站使用了 JavaScript 发送请求,所以你需要在服务器上才能正常运行,否则可能会出现跨域请求问题。