大海话语 2021-10-26 16:15 采纳率: 87.6%
浏览 159
已结题

怎么将input标签输入的内容,用div提交到后台查询

用input输入,然后点击查询,后台需要的input输入的数据为空呢?


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title></title>
    <script src="js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
    <style>
        body {
            background-color: #EEEEEE;
            margin: 0px;
            padding: 0px;
        }

        table {
            border-collapse: collapse;
            table-layout: fixed;
        }

        table, td, th {
            border: 1px solid #888;
            text-align: center;
        }

        .main {
            width: 600px;
            height: 300px;
            background-color: #FFFFFF;
            padding: 10px;
            margin: 10px auto;
            position: relative;
        }

        .main .content {
            width: 300px;
        }

        .empty {
            text-align: center;
            padding: 4px;
            display: block;
            border: 0px solid #888;
            border-width: 0px 1px 1px 1px;
        }

        .main .tId {
            width: 100px;
        }

        .main .tName {
            width: 100px;
        }

        .main .tAddress {
            width: 100px;
        }
    </style>
    <script>

    </script>
</head>

<body>
<h1 style="text-align: center">土星音乐</h1>
<div class="main"><br>
<!--    <form action="http://localhost:8080/singleNameAccurately">-->
<!--        <input type="text" id="text001" name="singleName" placeholder="输入歌名"/></td>-->
<!--        <input type="submit" value="查询" id="query" onclick="query()">-->
<!--    </form>-->
    <input type="text" id="text001" name="singleName" placeholder="输入歌名"/></td>
    <button type="submit" value="查询" id="query" onclick="query()" >查询</button>
    <!--    <button onclick="query()">查询</button><br><br>-->

    <div class="content">
        <table>
            <thead>
            <tr>
                <th class="tId">序号</th>
            </tr>
            <tr>
                <th class="tName">歌曲</th>
            </tr>
            <tr>
                <th class="tAddress">链接</th>
            </tr>
            </thead>
            <tbody></tbody>
        </table>
        <div class="empty">
            现在没有数据
        </div>
    </div>
</div>
</body>
<script>
    function content() {
        var text001 = document.getElementById(text001);
        return text001;
    }
    //查询
    function query() {
        $.ajax({
            type: "post",
            url: "http://localhost:8080/singleNameAccurately",
            dataType: "json",
            data: content.valueOf(),
            success: function (resp) {
                show(resp);
            }
        });
    }

    //格式化数据并在class="main"的标签的中<tbody>中显示
    function show(result) {
        var cont = $(".main tbody");
        cont.html(""); //清空
        for (var row of result) {
            var str =
                "<tr>" + "<td>" + row.id + "</td>" + "</tr>" +
                "<tr>" + "<td>" + row.singleName + "</td>" + "</tr>" +
                "<tr>" + "<td>" + row.link + "</td>" + "</tr>";
            cont.append(str);
        }
        //没有数据把空的内容显示出来
        if (result.length > 0)
            $(".empty").hide();
        else
            $(".empty").show();
    }

</script>
</html>
  • 写回答

7条回答 默认 最新

  • been_ss 2021-10-26 16:21
    关注

    哈喽,初步认为是这个content有问题,content你定义为函数,应该用content()获取值

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

问题事件

  • 系统已结题 11月3日
  • 已采纳回答 10月26日
  • 创建了问题 10月26日

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教