web 实验6

<!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">
    <!-- 手机端设置代码1 -->
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>王安妮-202031050293-实验6</title>
    <!-- 手机端设置代码2 -->
    <script type="text/javascript">
        function setRootFontSize() {
            var rootHtml = document.documentElement;
            var rem = rootHtml.clientWidth / (1080 / 100);   //1080为设计图px宽度
            rootHtml.style.fontSize = rem + "px";
        }
        setRootFontSize();   //网页首次载入时执行一次
        window.addEventListener("resize", setRootFontSize, false);   //网页大小改变时执行
        window.addEventListener("orientationchange", setRootFontSize, false);   //横屏切换时执行
    </script>
    <style>
        body {
            margin: 0;
        }

        #write {
            /* 定位在头部 */
            position: fixed;
            top: 0;
            width: auto;
        }

        #write input {
            float: left;
            width: auto;
        }

        #write button {
            float: left;
            margin-left: .2rem;
        }

        #showArea {
            width: auto;
            height: 5rem;
            background-color: #ffffff;
            margin-top: 1rem;
            border: 1px solid #000;
        }

        li {
            font-size: .1rem;
        }

        #mengingshow {
            font-size: .2rem;
            width: 100%;
            height: 5rem;
        }
        #a{
            font-size: .2rem;
            width: 100%;
            height: 5rem;
        }
    </style>
    <script src="js/jquery-3.1.1.min.js"></script>
    <script>

        $(document).ready(function () {
            $("#write input").on("input", function () {
                var paras = {
                    word: $("#write input").val(),
                    max: 20
                };
                $.ajax({
                    url: "http://43.136.217.18:8081/getSimilarWords",
                    data: paras,
                    type: "GET",
                    dataType: "json",
                    // 访问成功
                    success: function (res) {
                        //   将数据打印出来(或者点开网络中的文件,打开复制)
                        // document.write(JSON.stringify(res))
                        // 数据:{"content":[],"msg":"相似词汇列表","state":"SUC","time":"2023-04-21 15:09:44"}
                        if (res.state == "SUC") {
                            html = "<ul>";
                            for (var i = 0; i < res.content.length; i++) {
                                html += "<li>" + res.content[i] + "</li>";
                            }
                            html += "</ul>";
                            $("#showArea").html(html);
                            // 点击列表中的一个进行查询
                            $("li").on("click", function () {
                                var word = $(this).text();//获取词汇
                                // alert(word);
                                // 拿获取到的词汇进行查询
                                $.ajax({
                                    url: "http://43.136.217.18:8081/getWordDetail",
                                    data: { word: word },
                                    type: "GET",
                                    dataType: "json",
                                    success: function (res) {
                                        // {"content":[{"eng":"input","trans":[{"chn":["输入","投入的资金"],"pos":["n."]}]}],"msg":"词汇解释","state":"SUC","time":"2023-04-21 16:22:11"}
                                        if (res.state == "SUC") {
                                            var html = "<div id='mengingshow'>";
                                            for (var i = 0; i < res.content.length; i++) {
                                                html += "<div><tr>"
                                                var meaningpart = res.content[i]; //content部分
                                                meaning = meaningpart.trans;//trans部分
                                                for (var j = 0; j < meaning.length; j++) {
                                                    var result1 = meaning[j].pos;  //词性
                                                    var result2 = meaning[j].chn;  //词义
                                                }
                                                html += "<td>" + word + "</td>" + "<td>" + result1 + result2 + "</td>"


                                                html += "</tr></div>"



                                            }
                                            html += "</div>"
                                            $("#showArea").html(html)





                                        }

                                    },

                                })
                            })
                            // 点击查询按钮查询
                            $("button").on("click", function () {
                                word = $("#write input").val()//获取文本框中的元素
                                $.ajax({
                                    url: "http://43.136.217.18:8081/getWordDetail",
                                    data: { word: word },
                                    type: "GET",
                                    dataType: "json",
                                    success: function (res) {
                                        if (res.state == "SUC") {
                                            html = "<div id='a'>"
                                            for (var i = 0; i < res.content.length; i++) {
                                                html += "<div><tr>";
                                                var trans = res.content[i].trans; //trans
                                                // alert(trans)
                                                for (var j = 0; j < trans.length; j++) {
                                                    result1 = trans[j].pos;
                                                    result2 = trans[j].chn;
                                                }
                                                html += "<td>" + word + "</td>"  + "<td>" +result1 + result2 + "</td>"
                                                html += "<tr></div>";

                                            }
                                            html += "</div>"
                                            $("#showArea").html(html)
                                        }




                                    },

                                })
                            })


                        }
                        else {
                            $("showArea").html(res.msg);
                        }

                    },
                    error: function () {
                        var errMSG = "系统错误消息";
                        $("#showArea").text(errMSG);

                    }
                })

            })

        })
    </script>

</head>

<body>
    <div id="write">
        <input type="text" placeholder="请输入英文单词">
        <button>查询</button>

    </div>
    <div id="showArea"></div>

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值