web--test6 Web前端综合应用

<!--
 * @Author: nuo
 * @Date: 2023-04-23 05:46:04
 * @LastEditTime: 2023-04-23 17:39:07
 * @FilePath: \test6\dict.html
-->
<!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>zn--test6</title>
    <script src="jquery.min.js"></script>
    <script>
      $().ready(function () {
        $("#wordarea #inp").on("input", function () {
          $.ajax({
            url: "http://43.136.217.18:8081/getSimilarWords",
            data: { word: $(this).val() },
            type: "GET",
            datatype: "json",
            success: function (jsondata) {
              if (jsondata.state == "SUC") {
                var html = "<ul>";
                for (var i in jsondata.content) {
                  html += "<li>" + jsondata.content[i] + "</li>";
                }
                html += "</ul>";
                $("#area").html(html);
                $("#area li").on("click", function () {
                  $("#wordarea #inp").val($(this).text());
                  searchword($("#wordarea #inp").val());
                });
              }
            },
          });
        });
      });
      $("#searcharea #inp").click(function () {
        searchword($("#wordarea #inp").val());
      });
      function searchword(word) {
        $.ajax({
          url: "http://43.136.217.18:8081/getWordDetail",
          data: { word: word },
          type: "GET",
          dataType: "json",
          success: function (jsondata) {
            if (jsondata.state == "SUC") {
              $("#area").html("");
              var eng = "<div>" + jsondata.content[0].eng + "</div>";
              var html = "<ul>" + "<li>" + jsondata.content[0].eng + "</li>";
              for (var j in jsondata.content) {
                for (var i in jsondata.content[j].trans) {
                  html +=
                    "<li>" +
                    jsondata.content[j].trans[i].pos +
                    jsondata.content[j].trans[i].chn +
                    "</li>";
                }
                html += "<hr>";
              }
              html += "</ul>";
              $("#area").html(html);
            }
          },
        });
      }
    </script>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      #header {
        position: relative;
        top: 20px;
        left: 10px;
      }
      #wordarea #inp {
        width: 100%;
      }
      #wordarea {
        margin-right: 70px;
      }
      #searcharea {
        float: right;
        width: 50px;
      }
      
      ul {
        list-style: none;
        margin-left: 10px;
        margin-top: 20px;
        font-size: 13px;
      }
      ul li {
        padding-top: 5px;
        padding-bottom: 10px;
      }
      li:hover {
        cursor: pointer;
        background: gainsboro;
      }
    </style>
  </head>
  <body>
    <div id="header">
      <div id="searcharea"><button id="btn">查词</button></div>
      <div id="wordarea">
        <input id="inp" type="text" placeholder="请输入英文词汇" />
      </div>
    </div>
    <div id="area"></div>
  </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个简单的Web串口调试助手的后端和前端代码示例。 后端代码使用Python Flask框架实现,通过Flask-SocketIO实现实时通信: ```python from flask import Flask, render_template from flask_socketio import SocketIO, emit import serial app = Flask(__name__) app.config['SECRET_KEY'] = 'secret!' socketio = SocketIO(app) ser = serial.Serial('/dev/ttyUSB0', 115200) @app.route('/') def index(): return render_template('index.html') @socketio.on('connect') def test_connect(): emit('response', {'data': 'Connected'}) @socketio.on('disconnect') def test_disconnect(): print('Client disconnected') @socketio.on('message') def handle_message(msg): print('Received message: ' + msg) ser.write(msg.encode()) response = ser.readline().decode() emit('response', {'data': response}) if __name__ == '__main__': socketio.run(app) ``` 前端代码使用HTML、CSS和JavaScript实现,通过Socket.IO库实现与后端的实时通信: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Web Serial Console</title> <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script> <script src="https://code.jquery.com/jquery-1.11.1.js"></script> <style> body { margin: 0; font-family: Arial, Helvetica, sans-serif; } #terminal { width: 100%; height: 500px; background-color: #000; color: #fff; font-size: 14px; overflow-y: scroll; padding: 10px; } #input { width: 100%; height: 50px; font-size: 14px; padding: 10px; box-sizing: border-box; } </style> </head> <body> <div id="terminal"></div> <input id="input" type="text" placeholder="Enter command..."> <script> var socket = io.connect('http://' + document.domain + ':' + location.port); socket.on('response', function(msg) { $('#terminal').append(msg.data); $('#terminal').scrollTop($('#terminal')[0].scrollHeight); }); $('#input').keypress(function(event) { if (event.which == 13) { event.preventDefault(); var msg = $('#input').val(); $('#terminal').append('> ' + msg + '\n'); $('#input').val(''); socket.send(msg); } }); </script> </body> </html> ``` 注意:上述代码仅为示例,实际应用中需要根据具体需求进行修改和优化。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nuo__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值