0

我使用 mvc4/razor,在 VS 2012 中,我尝试使用 up 和 down 按钮上下移动 mvc 列表框中的项目。这些是我在 listorder/index.cshtml 中的控件我尝试了脚本,但这在这里不起作用。请帮忙

     @{
         var Resource = new List<SelectListItem> { 
        new SelectListItem { Text = "res1", Value = "1"},
        new SelectListItem { Text = "res2", Value = "2" },
         new SelectListItem { Text = "res3", Value = "3" },
          new SelectListItem { Text = "res4", Value = "4" }
    };
}

@Html.ListBox("ListReorder", Resource, new { @class = "ListMain"})
<input type="button" value="Up"  id="ResUpButton" onclick="MoveUp()" /> <br /> 
         <input type="button" value="Down" id="ResDownButton" onclick="MoveDown()" />  



<script src="scripts/jquery-1[1].3.2.js" type="text/javascript"></script>
     <script type="text/javascript">
         function MoveDown() {
             var selectedOption = $('#ListReorder > option[selected]');
             var nextOption = $('#ListReorder > option[selected]').next("option");
             if ($(nextOption).text() != "") {             
                 $(selectedOption).remove();
                 $(nextOption).after($(selectedOption));
             }                
         }
         function MoveUp() {
             var selectedOption = $('#ListReorder > option[selected]');
             var prevOption = $('#ListReorder > option[selected]').prev("option");
             if ($(prevOption).text() != "") {
                 $(selectedOption).remove();
                 $(prevOption).before($(selectedOption));
             }
           }

    </script>
4

1 回答 1

0

尝试更多信息thisthis

$("#ResUpButton,#ResDownButton").live('click',function(event) {.....
于 2013-07-17T05:55:18.310 回答