什么是MVVM框架

2023-04-24by@987811032-4QhuC&@ChatGPT.Model: gpt-3.5
987811032-4QhuC

什么是MVVM框架

Avatar
Avatar

MVVM框架是一种前端开发框架,它是Model-View-ViewModel的缩写,是一种将业务逻辑、视图逻辑和UI逻辑分离的架构模式。其中,Model表示数据模型,ViewModel是视图模型,View则是用户界面。MVVM框架的主要目的是将数据与视图分离,通过ViewModel来处理数据和业务逻辑,并将数据绑定到视图上,从而实现动态更新视图的效果。MVVM框架的优点是代码清晰、易于维护、可重用性高等。常见的MVVM框架有AngularJS、Vue.js和React等。

987811032-4QhuC

可以用HTML+CSS+JAVA+Javasript写一个在线考试系统的登录页面吗?

Avatar
Avatar

是的,可以使用HTML、CSS、Javascript和Java等技术来开发一个在线考试系统的登录页面。以下是一个简单的示例:

HTML代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>在线考试系统登录页面</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="login-box">
        <h2>在线考试系统</h2>
        <form>
            <div class="user-box">
                <input type="text" name="username" required="">
                <label>用户名</label>
            </div>
            <div class="user-box">
                <input type="password" name="password" required="">
                <label>密码</label>
            </div>
            <a href="#">
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                登录
            </a>
        </form>
    </div>
</body>
</html>

CSS代码:

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: sans-serif;
    background: #f1f1f1;
}

.login-box {
    width: 400px;
    height: 450px;
    background: #fff;
    color: #333;
    top: 50%;
    left: 50%;
    position: absolute;
    transform: translate(-50%, -50%);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    padding: 70px 30px;
    text-align: center;
}

.login-box h2 {
    font-size: 30px;
    font-weight: 500;
    margin-bottom: 40px;
}

.user-box {
    position: relative;
    margin-bottom: 35px;
}

.user-box input {
    width: 100%;
    padding: 10px 0;
    font-size: 16px;
    color: #333;
    margin-bottom: 30px;
    border: none;
    border-bottom: 2px solid #adadad;
    outline: none;
    background: transparent;
}

.user-box label {
    position: absolute;
    top: 0;
    left: 0;
    padding: 10px 0;
    font-size: 16px;
    color: #adadad;
    pointer-events: none;
    transition: 0.5s;
}

.user-box input:focus ~ label,
.user-box input:valid ~ label {
    top: -20px;
    font-size: 12px;
    color: #00bcd4;
}

a {
    display: inline-block;
    background: #00bcd4;
    color: #fff;
    padding: 10px 30px;
    margin-top: 40px;
    position: relative;
    text-decoration: none;
    font-size: 16px;
    letter-spacing: 2px;
    border-radius: 5px;
    border: none;
    transition: 0.5s;
    overflow: hidden;
}

a:hover {
    background: #fff;
    color: #00bcd4;
}

a span {
    position: absolute;
    display: block;
}

a span:nth-child(1) {
    top: 0;
    left: -100%;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #00bcd4);
}

a:hover span:nth-child(1) {
    left: 100%;
    transition: 0.5s;
}

a span:nth-child(2) {
    top: -100%;
    right: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, transparent, #00bcd4);
}

a:hover span:nth-child(2) {
    top: 100%;
    transition: 0.5s;
    delay: 0.25s;
}

a span:nth-child(3) {
    bottom: 0;
    right: -100%;
    width: 100%;
    height: 2px;
    background: linear-gradient(270deg, transparent, #00bcd4);
}

a:hover span:nth-child(3) {
    right: 100%;
    transition: 0.5s;
    delay: 0.5s;
}

a span:nth-child(4) {
    top: -100%;
    left: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(360deg, transparent, #00bcd4);
}

a:hover span:nth-child(4) {
    top: 100%;
    transition: 0.5s;
    delay: 0.75s;
}

Javascript代码:

// 登录按钮点击事件
document.querySelector('a').addEventListener('click', function(event) {
    event.preventDefault(); // 阻止默认行为
    var username = document.querySelector('input[name="username"]').value;
    var password = document.querySelector('input[name="password"]').value;
    // TODO: 验证用户名和密码是否正确
    alert('登录成功!');
});

Java代码:

// TODO: 实现登录功能
987811032-4QhuC

把Javascript代码的书写方式改为jquery

Avatar
Avatar

以下是使用jQuery重写的Javascript代码:

// 登录按钮点击事件
$('a').on('click', function(event) {
    event.preventDefault(); // 阻止默认行为
    var username = $('input[name="username"]').val();
    var password = $('input[name="password"]').val();
    // TODO: 验证用户名和密码是否正确
    alert('登录成功!');
});

需要先在HTML页面中引入jQuery库文件。例如:

<head>
    <meta charset="UTF-8">
    <title>在线考试系统登录页面</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
987811032-4QhuC

在页面输入项中添加用户类型选择用下拉菜单选择,可以选择学生、教师、管理员

Avatar
Avatar

Usage limit reached 🤕
Each user can chat for free 10 times a day
Please [Upgrade to PRO] to expand the limit

987811032-4QhuC

在页面输入项中添加用户类型选择用下拉菜单选择,可以选择学生、教师、管理员

Avatar
Avatar

可以在登录框中添加一个下拉菜单,供用户选择用户类型。以下是一个示例:

HTML代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>在线考试系统登录页面</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="login-box">
        <h2>在线考试系统</h2>
        <form>
            <div class="user-box">
                <input type="text" name="username" required="">
                <label>用户名</label>
            </div>
            <div class="user-box">
                <input type="password" name="password" required="">
                <label>密码</label>
            </div>
            <div class="user-box">
                <select name="usertype" required="">
                    <option value="">请选择用户类型</option>
                    <option value="student">学生</option>
                    <option value="teacher">教师</option>
                    <option value="admin">管理员</option>
                </select>
            </div>
            <a href="#">
                <span></span>
                <span></span>
                <span></span>
                <span></span>
                登录
            </a>
        </form>
    </div>
</body>
</html>

CSS代码:

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: sans-serif;
    background: #f1f1f1;
}

.login-box {
    width: 400px;
    height: 500px;
    background: #fff;
    color: #333;
    top: 50%;
    left: 50%;
    position: absolute;
    transform: translate(-50%, -50%);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    padding: 70px 30px;
    text-align: center;
}

.login-box h2 {
    font-size: 30px;
    font-weight: 500;
    margin-bottom: 40px;
}

.user-box {
    position: relative;
    margin-bottom: 35px;
}

.user-box input,
.user-box select {
    width: 100%;
    padding: 10px 0;
    font-size: 16px;
    color: #333;
    margin-bottom: 30px;
    border: none;
    border-bottom: 2px solid #adadad;
    outline: none;
    background: transparent;
}

.user-box input:focus ~ label,
.user-box input:valid ~ label,
.user-box select:focus ~ label,
.user-box select:valid ~ label {
    top: -20px;
    font-size: 12px;
    color: #00bcd4;
}

.user-box label {
    position: absolute;
    top: 0;
    left: 0;
    padding: 10px 0;
    font-size: 16px;
    color: #adadad;
    pointer-events: none;
    transition: 0.5s;
}

a {
    display: inline-block;
    background: #00bcd4;
    color: #fff;
    padding: 10px 30px;
    margin-top: 40px;
    position: relative;
    text-decoration: none;
    font-size: 16px;
    letter-spacing: 2px;
    border-radius: 5px;
    border: none;
    transition: 0.5s;
    overflow: hidden;
}

a:hover {
    background: #fff;
    color: #00bcd4;
}

a span {
    position: absolute;
    display: block;
}

a span:nth-child(1) {
    top: 0;
    left: -100%;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #00bcd4);
}

a:hover span:nth-child(1) {
    left: 100%;
    transition: 0.5s;
}

a span:nth-child(2) {
    top: -100%;
    right: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, transparent, #00bcd4);
}

a:hover span:nth-child(2) {
    top: 100%;
    transition: 0.5s;
    delay: 0.25s;
}

a span:nth-child(3) {
    bottom: 0;
    right: -100%;
    width: 100%;
    height: 2px;
    background: linear-gradient(270deg, transparent, #00bcd4);
}

a:hover span:nth-child(3) {
    right: 100%;
    transition: 0.5s;
    delay: 0.5s;
}

a span:nth-child(4) {
    top: -100%;
    left: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(360deg, transparent, #00bcd4);
}

a:hover span:nth-child(4) {
    top: 100%;
    transition: 0.5s;
    delay: 0.75s;
}

Javascript代码:

// 登录按钮点击事件
$('a').on('click', function(event) {
    event.preventDefault(); // 阻止默认行为
    var username = $('input[name="username"]').val();
    var password = $('input[name="password"]').val();
    var usertype = $('select[name="usertype"]').val();
    if (usertype === '') {
        alert('请选择用户类型!');
        return;
    }
    // TODO: 验证用户名和密码是否正确,根据用户类型进行相应的操作
    alert('登录成功!');
});
987811032-4QhuC

去掉输入框的阴影

Avatar
Avatar

An error occurred with your deployment

EDGE_FUNCTION_INVOCATION_TIMEOUT

987811032-4QhuC

去掉输入框的阴影

Avatar
Avatar

An error occurred with your deployment

EDGE_FUNCTION_INVOCATION_TIMEOUT

987811032-4QhuC

让每个输入框的间距变小一半

Avatar