jQuery控制表格行移动,序号不变

@model Gd.NetSign.Controllers.DTO.SysPamaterDTO
@{
    ViewBag.Title = "SysPamatList";
    //Layout = "~/Views/Masters/Frame.cshtml";
}
<script type="text/javascript">
    //检索
    function doSearch() {

        loading();
        $.ajax({
            type: "post",
            url: '/Spfsz/SysPamatList?SysPamaterName=' + $('#SysPamaterName').val() + "&SysPamaterRemark=" + $('#SysPamaterRemark').val() + "&ParentKeyName=" + "@Model.ParentKeyName",
            data: {},
            dataType: "html",
            error: function (msg) {

                unloading();

            },
            success: function (result) {
                $("#List").html(result);
                unloading();

            }
        });

    
    }
    //-->
    //保存
    function DoSave() {
        loading("数据提交中...请稍后");
        var previewOptions = {
            url: "/Spfsz/SaveSysPamat?isOder=1&ParentKeyName=" + "@Model.ParentKeyName",
            type: 'POST',
            //data:_list: _list,
            //beforeSubmit: submitCheck,
            iframe: false,
            success: function (result) {
                unloading();
                if (result.Success == true) {

                    $.Ok(result.Msg, function () {
                        loading();
                        $.ajax({
                            type: "post",
                            url: "/Spfsz/SysPamatList?ParentKeyName=" + "@Model.ParentKeyName",
                            data: {},
                            dataType: "html",
                            error: function (msg) {

                                unloading();

                            },
                            success: function (result) {
                                $("#List").html(result);
                                unloading();

                            }
                        });
                    });
                }
                if (result.Success == false) {
                    $.Error(result.Msg);
                }
            },
            error: function () {
                unloading();
            }
        };
        $("#OperaForm").ajaxSubmit(previewOptions);
        return false;
    }
    //保存
    function DoSaveSingle() {
        loading("数据提交中...请稍后");
        var previewOptions = {
            url: "/Spfsz/SaveSysPamat?ParentKeyName=" + "@Model.ParentKeyName",
            type: 'POST',
            //data:_list: _list,
            //beforeSubmit: submitCheck,
            iframe: false,
            success: function (result) {
                unloading();
                if (result.Success == true) {

                    $.Ok(result.Msg, function () {
                        loading();
                        $.ajax({
                            type: "post",
                            url: "/Spfsz/SysPamatList?ParentKeyName=" + "@Model.ParentKeyName",
                            data: {},
                            dataType: "html",
                            error: function (msg) {

                                unloading();

                            },
                            success: function (result) {
                                $("#List").html(result);
                                unloading();

                            }
                        });
                    });
                }
                if (result.Success == false) {
                    $.Error(result.Msg);
                }
            },
            error: function () {
                unloading();
            }
        };
        $("#OperaForm").ajaxSubmit(previewOptions);
        return false;
    }

</script>
<style>
    tr input {
        border: hidden;
        background-color: transparent;
        width: 100%;
        height: 20px;
        margin-left: 2px;
    }

    table tr td {
        text-align: left;
    }
</style>

   
        <div class="div_btnContainer">
            <span>参数名:</span><input  />
            <span>参数说明:</span><input  />
            <input type="button" class="btn" value="检索" onclick="doSearch();" />

            <input   type="button"   />
            <input type="button"  />
            <input type="button" class="btn" value="保存" @(Model.IsNullField == 1 ? "onclick=DoSave()" : "onclick=DoSaveSingle()") />
        </div>
        <form >
            <div class="form">
                <table >
                    <thead>
                        <tr>
                            <th  title="选择">选择</th>
                            <th  title="参数名">参数名</th>
                            <th  title="参数值">参数值</th>
                            <th  title="参数说明">参数说明</th>

                        </tr>
                    </thead>
                    <tbody>
                        @{string line = "";
                        var listLength = Model.SysPamaterList.Count();
                        for (int i = 0; i < listLength; i++)
                        {
                            line = "line" + (i + 1);
                            <tr >

                                <td>
                                    <input name="[@(i)].NodeIdx"  />
                                    <input hidden="hidden" name="[@(i)].NodeIdx"  />
                                </td>
                                <td title="@Model.SysPamaterList[i].KeyName" >
                                    <input type="text"  />
                                </td>
                                <td title="@Model.SysPamaterList[i].KeyValue" >
                                    <input type="text"  />
                                </td>
                                <td title="@Model.SysPamaterList[i].KeyDis"  >
                                    <input type="text"  />
                                    <input type="text"  />

                                </td>
                            </tr>
                        }
                        }
                    </tbody>
                </table>

            </div>
        </form>
    

<script language="javascript">

    var currentStep = new Array();
    var max_line_num = parseInt("@Model.SysPamaterList.Count()");
    //上移
    function up_exchange_line() {
        if (!checks())
            return;
        //升序
        currentStep.sort(function (a, b) { return a > b ? 1 : -1 });
        for (var i = 0; i < currentStep.length; i++) {
            if (currentStep[i] == 0 || currentStep[i] == null) {
                continue;
            }
            else {
                var upStep = currentStep[i] - 1;
                if (upStep < 1 || $('#line' + upStep + ' input[type="checkbox"]').attr("checked")) {
                    continue;
                }
                //取值
                var keynameNext = $("#line" + upStep + " input[]").val();
                var keyvalueNext = $("#line" + upStep + " input[]").val();
                var KeyDisNext = $("#line" + upStep + " input[]").val();
                var IsNewNetSignNext = $("#line" + upStep + " input[]").val();
                var keyname = $("#line" + currentStep[i] + " input[]").val();
                var keyvalue = $("#line" + currentStep[i] + " input[]").val();
                var KeyDis = $("#line" + currentStep[i] + " input[]").val();
                var IsNewNetSign = $("#line" + currentStep[i] + " input[]").val();
                //换值
                $("#line" + upStep + " input[]").val(keyname);
                $("#line" + upStep + " input[]").val(keyvalue);
                $("#line" + upStep + " input[]").val(KeyDis);
                $("#line" + upStep + " input[]").val(IsNewNetSign);
                $("#line" + currentStep[i] + " input[]").val(keynameNext);
                $("#line" + currentStep[i] + " input[]").val(keyvalueNext);
                $("#line" + currentStep[i] + " input[]").val(KeyDisNext);
                $("#line" + currentStep[i] + " input[]").val(IsNewNetSignNext);
               //修改选中
                $('#line' + upStep + ' input[type="checkbox"]').attr("checked", true);
                $('#line' + currentStep[i] + ' input[type="checkbox"]').attr("checked", false);
                currentStep[i] = upStep;

            }

        }

    }
    //下移
    function down_exchange_line() {
        if (!checks())
            return;
        //倒序
        currentStep.sort(function (a, b) { return a < b ? 1 : -1 });
        for (var i = 0; i < currentStep.length; i++) {
            if (currentStep[i] == "0" || currentStep[i] == null) {
                continue;

            }
            else {

                var nextStep = parseInt(currentStep[i]) + 1;
                if (nextStep > max_line_num || $('#line' + nextStep + ' input[type="checkbox"]').attr("checked")) {
                    continue;
                }
                //取值
                var keynameNext = $("#line" + nextStep + " input[]").val();
                var keyvalueNext = $("#line" + nextStep + " input[]").val();
                var KeyDisNext = $("#line" + nextStep + " input[]").val();
                var IsNewNetSignNext = $("#line" + nextStep + " input[]").val();
                var keyname = $("#line" + currentStep[i] + " input[]").val();
                var keyvalue = $("#line" + currentStep[i] + " input[]").val();
                var KeyDis = $("#line" + currentStep[i] + " input[]").val();
                var IsNewNetSign = $("#line" + currentStep[i] + " input[]").val();
                //换值
                $("#line" + nextStep + " input[]").val(keyname);
                $("#line" + nextStep + " input[]").val(keyvalue);
                $("#line" + nextStep + " input[]").val(KeyDis);
                $("#line" + nextStep + " input[]").val(IsNewNetSign);
                $("#line" + currentStep[i] + " input[]").val(keynameNext);
                $("#line" + currentStep[i] + " input[]").val(keyvalueNext);
                $("#line" + currentStep[i] + " input[]").val(KeyDisNext);
                $("#line" + currentStep[i] + " input[]").val(IsNewNetSignNext);
               //修改选中
                $('#line' + nextStep + ' input[type="checkbox"]').attr("checked", true);
                $('#line' + currentStep[i] + ' input[type="checkbox"]').attr("checked", false);
                currentStep[i] = nextStep;


            }
        }
    }
    //增加减少id值
    function chk(box) {
        if ($(box).attr("checked") == "checked") {
            //currentStep.push($(box).parent().parent().find("td").eq(0).text())
            currentStep.push(parseInt($(box).val()));
        }
        else {

            for (var i = 0; i < currentStep.length; i++) {
                if (currentStep[i] == $(box).val()) {
                    currentStep.remove(i);
                    //.remove(i);
                }

            }

        }

    }
    Array.prototype.remove = function (dx) {
        if (isNaN(dx) || dx > this.length) { return false; }
        for (var i = 0, n = 0; i < this.length; i++) {
            if (this[i] != this[dx]) {
                this[n++] = this[i]
            }
        }
        this.length -= 1
    }
    function checks() {
        var chk_value = [];
        $('input:checked').each(function () {
            chk_value.push($(this).val());
        });
        if (chk_value.length <= 0) {
            //alert("请选择一条数据");
             $.Warning('请选择一条数据!');
            return false;

        }
        return true;
    }
</script>