web实验四

实验目的及要求:

  1. 掌握Jquery页面初始化方法
  2. 掌握Jquery的选择器的基本使用
  3. 掌握Jquery对DOM 的基本操作
  4. 掌握vue的基础用法

实验内容:

说明所有实验内容可选择jquery或vue的任一项技术路线实现

1.使用jquery或vue实现如下界面效果:

提示

  • 奇数行背景色:#FFF38F;偶数行背景色:#FFFFEE;选中行:#FF6500
  • 选中行时,设置单选框选中状态
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 500px;
            border-collapse: collapse;
            text-align: center;
        }
        th, td {
            border: 1px solid #000;
        }
    </style>
</head>

<body>
    <table>
        <tr>
            <th></th>
            <th>姓名</th>
            <th>性别</th>
            <th>暂住地</th>
        </tr>
        <tr>
            <td><input type="radio" name="" id=""></td>
            <td>张三</td>
            <td>男</td>
            <td>四川成都</td>
        </tr>
        <tr>
            <td><input type="radio" name="" id=""></td>
            <td>李四</td>
            <td>女</td>
            <td>四川绵阳</td>
        </tr>
        <tr>
            <td><input type="radio" name="" id=""></td>
            <td>王五</td>
            <td>男</td>
            <td>四川南充</td>
        </tr>
        <tr>
            <td><input type="radio" name="" id=""></td>
            <td>赵六</td>
            <td>男</td>
            <td>四川自贡</td>
        </tr>
        <tr>
            <td><input type="radio" name="" id=""></td>
            <td>陈勇</td>
            <td>男</td>
            <td>四川德阳</td>
        </tr>
        <tr>
            <td><input type="radio" name="" id=""></td>
            <td>罗梅</td>
            <td>女</td>
            <td>四川宜宾</td>
        </tr>
    </table>
    <script src="./实验六/js/jquery-3.6.3.min.js"></script>

    <script>
        $('table tr:odd').css("background-color", "#FFF38F")
        $('table tr:even').css("background-color", "#FFFFEE")
        $(':radio').on("click", function() {
            $(this).parent().parent().css("background-color", "#FF6500")
        })


    </script>
</body>

</html>

2.使用jquery或vue实现内容过滤,效果如下图所示:

提示

  • Jquery中提供了filter方法进行过滤,$("选择器").filter(内容过滤器)
  • 搜索过程中可先隐藏hide所有数据行,满足条件的行进行显示show()
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 500px;
            border-collapse: collapse;
            text-align: center;
        }
        th, td {
            border: 1px solid #000;
        }
        #search {
            margin-bottom: 20px;
        }
    </style>
</head>

<body>
    <div id="search">查询:<input type="text"></div>
   
    <table>
        <tr>
            <th>姓名</th>
            <th>性别</th>
            <th>暂住地</th>
        </tr>
        <tr>
            <td>张三</td>
            <td>男</td>
            <td>浙江宁波</td>
        </tr>
        <tr>
            <td>李四</td>
            <td>女</td>
            <td>浙江杭州</td>
        </tr>
        <tr>
            <td>王五</td>
            <td>男</td>
            <td>湖南长沙</td>
        </tr>
        <tr>
            <td>赵六</td>
            <td>男</td>
            <td>浙江温州</td>
        </tr>
        <tr>
            <td>Rain</td>
            <td>男</td>
            <td>浙江杭州</td>
        </tr>
        <tr>
            <td>王六</td>
            <td>女</td>
            <td>浙江杭州</td>
        </tr>
    </table>
    <script src="./实验六/js/jquery-3.6.3.min.js"></script>

    <script>
        $('table tr:odd').css("background-color", "#FFF38F")
        $('table tr:even').css("background-color", "#FFFFEE")

        $("#search input").change(function() {
            $("tr:not(:first)").hide()
            $("table tr").filter(":contains(" + $(this).val() + ")").show()
        })
    </script>
</body>

</html>

3.使用 JQuery或vue 实现级联选择框,界面实现效果参考如下图。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <form action="">
        <select id="province">
            <option>请选择...</option>
            <option>河北省</option>
            <option>湖北省</option>
            <option>四川省</option>
        </select>
        <select id="city">
            <option>请选择...</option>
        </select>
    </form>

    <script src="./实验六/js/jquery-3.6.3.min.js"></script>
    <script>
        $("#province").change(function () {
            let arrCity = [[],
                ["石家庄", "邯郸", "唐山", "张家口"],
                ["武汉", "恩施"],
                ["成都", "绵阳", "泸州"]
            ]

            let city = document.getElementById("city")
            let cityChildNodes = city.childNodes;
            for( let i=2; i < cityChildNodes.length; ) {
                city.removeChild(cityChildNodes[i])
            }

            let province = document.getElementById("province")
            let index = province.selectedIndex
            for( j=0; j<arrCity[index].length; j++) {
                $("#city").append("<option>" +arrCity[index][j]+ "</option>")
            }
        })
    </script>

</body>

</html>

4.使用Jquery或vue实现将输入数据添加至表格中,通过点击Delete可删除所在行数据。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .addFrom {
            width: 800px;
            height: 150px;
            margin: 0 auto;
            text-align: center;
            border-bottom: 1px solid #000;
        }
        .title {
            text-align: center;
            font-size: 20px;
            margin-bottom: 20px;
        }
        .submit input{
            margin: 20px auto;
        }
        table {
            width: 400px;
            margin: 0 auto;
            margin-top: 50px;
            border-collapse: collapse;
            text-align: center;
            line-height: 30px;

        }
        th, td{
            border: 1px solid #000;
        }

    </style>
</head>
<body>
    <div class="addFrom">
        <div class="title">添加新员工</div>
        name: <input type="text" id="name">&nbsp;&nbsp;
        email: <input type="text" id="email">&nbsp;&nbsp;
        salary: <input type="text" id="salary">

        <div class="submit">
            <input type="button" value="Submit" id="submit">
        </div>
    </div>

    <table>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Salary</th>
            <th></th>
        </tr>
    </table>

    <script src="./实验六/js/jquery-3.6.3.min.js"></script>
    <script>
        $("#submit").click(function() {
            let name = $("#name").val()
            let email = $("#email").val()
            let salary = $("#salary").val()
            $("table").append(`
                <tr>
                    <td>${name}</td>
                    <td>${email}</td>
                    <td>${salary}</td>
                    <td><a href="#" id="del" onclick="del(this)">Delete</a></td>
                </tr>
            `)
        })
        $(document).on("click", "#del", function() {
            $(this).parent().parent().remove()
        })

        // function del(row) {
        //     $(row).parent().parent().remove()
        // }

        //为啥子不行!!!!
        // $("#del").click(function() {
        //     $(this).parent().parent().remove()
        // })

    </script>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值