网页第一次作业

HTML实现注册登录页面跳转

要求:

- 主页中,可以点击 **注册**或者**登录**能直接在新窗口跳转到对应的页面
- 登录页面中,输入账号、密码可以点击登录-自动跳转到主页
- 注册页面中,输入账号、密码、确认密码、昵称,点击注册,注册后自动跳转到登录页面

以下为代码与实现图例

主页:

代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
        }
        button {
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            border: none;
            background-color: #eb097a;
            color: white;
            margin: 4px 2px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <h1>欢迎来到主页</h1>
    <button onclick="window.open('注册.html', '_blank')">注册</button>
    <button onclick="window.open('登录.html', '_blank')">登录</button>
</body>
</html>

图例

登录

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
        }
        input[type=text], input[type=password] {
            width: 30%;
            padding: 12px 20px;
            margin: 8px 0;
            display: inline-block;
            border: 1px solid #ccc;
            box-sizing: border-box;
        }
        button {
            background-color: #eb097a;
            color: white;
            padding: 14px 20px;
            margin: 8px 0;
            border: none;
            cursor: pointer;
            width: 30%;
        }
    </style>
</head>
<body>
    <h1>登录</h1>
    <form>
        <label for="username">账号:</label><br>
        <input type="text" id="username" name="username"><br>
        <label for="password">密码:</label><br>
        <input type="password" id="password" name="password"><br><br>
        <button type="button" onclick="window.location.href = '主页.html'">登录</button>
    </form>
</body>
</html>

图例

注册

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
        }
        input[type=text], input[type=password] {
            width: 30%;
            padding: 12px 20px;
            margin: 8px 0;
            display: inline-block;
            border: 1px solid #ccc;
            box-sizing: border-box;
        }
        button {
            background-color: #eb097a;
            color: white;
            padding: 14px 20px;
            margin: 8px 0;
            border: none;
            cursor: pointer;
            width: 30%;
        }
    </style>
</head>
<body>
    <h1>注册</h1>
    <form>
        <label for="username">账号:</label><br>
        <input type="text" id="username" name="username"><br>
        <label for="password">密码:</label><br>
        <input type="password" id="password" name="password"><br>
        <label for="confirmPassword">确认密码:</label><br>
        <input type="password" id="confirmPassword" name="confirmPassword"><br>
        <label for="nickname">昵称:</label><br>
        <input type="text" id="nickname" name="nickname"><br><br>
        <button type="button" onclick="window.location.href = '登录.html'">注册</button>
    </form>
</body>
</html>

图例

### Web前端初学者第一次作业示例教程 对于初次接触Web前端的学生来说,完成第一个项目可以是一个非常有意义的经历。下面提供了一个简单的HTML、CSS和JavaScript相结合的小型网页设计案例。 #### 1. HTML结构搭建 创建一个基础的HTML文档作为页面的基础架构。这里展示的是一个描述南京旅游景点的信息页: ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>南京旅游指南</title> <link rel="stylesheet" href="styles.css"> </head> <body> <header> <h1>欢迎来到六朝古都—南京</h1> </header> <nav> <ul> <li><a href="#紫金山">紫金山天文台</a></li> <li><a href="#夫子庙">夫子庙秦淮风光带</a></li> <!-- 更多链接 --> </ul> </nav> <main> <section id="紫金山"> <h2>紫金山天文台</h2> <p>位于南京市东郊...</p> </section> <section id="夫子庙"> <h2>夫子庙秦淮风光带</h2> <p>中国著名的开放式文化景区之一...</p> </section> <!-- 添加更多部分 --> </main> <footer> 版权声明 © 2023 南京旅游网 </footer> <script src="scripts.js"></script> </body> </html> ``` 这段代码定义了整个页面的大致布局,并引入外部样式表`styles.css`以及脚本文件`scripts.js`[^1]。 #### 2. CSS样式美化 接下来编写一些基本的CSS规则来增强视觉效果。这不仅能使页面看起来更美观,还能帮助理解如何利用层叠样式表控制元素外观: ```css /* styles.css */ * { margin: 0; padding: 0; } body { font-family: Arial, sans-serif; line-height: 1.6em; } header h1 { text-align: center; color: #fff; background-color: #7B68EE; padding: .5rem; } nav ul { list-style-type: none; display: flex; justify-content: space-around; background-color: #f4f4f4; padding: .5rem; } nav a { text-decoration: none; color: black; } main section { max-width: 960px; margin: auto; padding: 1rem; } ``` 上述CSS片段实现了对文字颜色、背景色以及其他属性的基本设定,使得页面具有一定的美感[^2]。 #### 3. JavaScript交互功能实现 最后,在`scripts.js`中加入少量JavaScript代码以增加互动性。比如当用户点击导航栏中的某个条目时滚动到相应位置的功能: ```javascript // scripts.js document.querySelectorAll('nav a').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); ``` 以上就是针对Web前端新手的一个完整的入门级练习项目概述。它涵盖了HTML标记语言的应用、CSS样式的运用以及初步了解JavaScript编程的概念。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值