zhangzijiez 2018-05-02 07:51 采纳率: 38.5%
浏览 1409
已结题

td点击编辑问题 请教一下

jq遍历table怎么进行点击td进行编辑

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分页</title>
<script type="text/javascript"
    src="${pageContext.request.contextPath}/jquery-easyui/jquery.min.js"></script>
<script type="text/javascript"
    src="${pageContext.request.contextPath}/jquery-easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
    src="${pageContext.request.contextPath}/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
    $(function() {
        $("#cha")
                .click(
                        function() {
                            $
                                    .ajax({
                                        url : 'msg/selHis',
                                        type : 'POST',
                                        dataType : 'json',
                                        data : {
                                            StartDate : $("#qi").val(),
                                            EndDate : $("#zi").val()
                                        },
                                        success : function(msg) {
                                            var tb = document
                                                    .getElementById("set");
                                            for (var n = tb.rows.length - 1; n > 0; n--) {
                                                tb.deleteRow(n);
                                            }
                                            for (i = 0; i < msg.length; i++) {
                                                $("#set")
                                                        .append(
                                                                "<tr><td><input class = 'check' type='checkbox'></td><td>"
                                                                        + (msg[i].yybh == undefined ? " "
                                                                                : msg[i].yybh)
                                                                        + "</td><td>"
                                                                        + (msg[i].jyckh == undefined ? " "
                                                                                : msg[i].jyckh)
                                                                        + "</td><td>"
                                                                        + (msg[i].posjysj == undefined ? " "
                                                                                : msg[i].posjysj)
                                                                        + "</td><td>"
                                                                        + (msg[i].sfzhm == undefined ? " "
                                                                                : msg[i].sfzhm)
                                                                        + "</td><td>"
                                                                        + (msg[i].jylx == undefined ? " "
                                                                                : msg[i].jylx)
                                                                        + "</td><td>"
                                                                        + (msg[i].posjyje == undefined ? " "
                                                                                : msg[i].posjyje)
                                                                        + "</td><td>"
                                                                        + (msg[i].shh == undefined ? " "
                                                                                : msg[i].shh)
                                                                        + "</td><td>"
                                                                        + (msg[i].zdbh == undefined ? " "
                                                                                : msg[i].zdbh)
                                                                        + "</td><td>"
                                                                        + (msg[i].bhcfybz == undefined ? " "
                                                                                : msg[i].bhcfybz)
                                                                        + "</td><td>"
                                                                        + (msg[i].bz1 == undefined ? " "
                                                                                : msg[i].bz1)
                                                                        + "</td><td>"
                                                                        + (msg[i].bz2 == undefined ? " "
                                                                                : msg[i].bz2)
                                                                        + "</td><td>"
                                                                        + (msg[i].bz3 == undefined ? " "
                                                                                : msg[i].bz3)
                                                                        + "</td></tr>")
                                            }
                                        }
                                    });
                        });
        $('table tr td').click(
                function() {
                    if (!$(this).is('.input')) {
                        $(this).addClass('input').html(
                                '<input type="text" value="' + $(this).text()
                                        + '" />').find('input').focus().blur(
                                function() {
                                    var thisid = $(this).parent().siblings(
                                            "th:eq(0)").text();
                                    var thisvalue = $(this).val();
                                    var thisclass = $(this).parent().attr(
                                            "class");

                                    $.ajax({
                                        type : 'POST',
                                        url : 'update.php',
                                        data : "thisid=" + thisid
                                                + "&thisclass=" + thisclass
                                                + "&thisvalue=" + thisvalue
                                    });
                                    $(this).parent().removeClass('input').html(
                                            $(this).val() || 0);
                                });
                    }
                }).hover(function() {
            $(this).addClass('hover');
        }, function() {
            $(this).removeClass('hover');
        });

    });
</script>

</head>
<body>
    <div>
        起:<input id="qi" class="easyui-datebox" /> 止:<input id="zi"
            class="easyui-datebox" /> <input id="cha" type="button" value="查询" />
        <input id="upload" type="button" value="上传选中交易">
        <table id="set" border="1" cellpadding="0" cellspacing="0"
            bordercolor="E7F0FF">
            <tr bgcolor="E7F0FF">
                <th>选择</th>
                <th>医药机构编号</th>
                <th>POS签购单交易参考号</th>
                <th>POS交易时间</th>
                <th>身份证号码</th>
                <th>交易类型</th>
                <th>POS交易金额</th>
                <th>商户号</th>
                <th>终端编号</th>
                <th>包含处方药标志</th>
                <th>备注1</th>
                <th>备注2</th>
                <th>备注3</th>
            </tr>
        </table>
    </div>
</body>
</html>
  • 写回答

7条回答 默认 最新

  • hezkvectory 2018-05-02 07:57
    关注

    点击td时,把当前td内容隐藏,换成input标签,就能编辑了,建议使用jquery easyui,里面功能丰富

    评论

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗