1

我正在使用asmselect插件来允许用户从选择框中选择和订购多个项目。

我只想在用户进行更改时启用提交按钮。以下方法有效,但在对选定元素进行排序时不会调用更改:

<script type="text/javascript">
  $(document).ready(function() {
    $("select[multiple]").asmSelect({
      addItemTarget: 'bottom',
      highlight: false,
      hideWhenAdded: true,
      sortable: true
    });
    // track changes with our own event
    $("#mySelect").change(function(e, data) {
      $("#submit").removeAttr("disabled");

      // if it's a sort or an add, then give it a little color animation to highlight it
      if (data.type != 'drop') data.item.animate({ 'backgroundColor': '#ffffcc' }, 20, linear', function() {
        data.item.animate({ 'backgroundColor': '#dddddd' }, 500);
    });
  });
}); 
</script>

选择并提交:

<select id="mySelect" multiple="multiple" name="mySelect[]" title="Select Elements">
  <% foreach (var item in Model)
     { %>
  <option <%= item.Selected ? "selected=selected" : "" %> value="<%= Html.Encode(item.ID) %>">
    <%= Html.Encode(item.Text) %></option>
  <% } %>
</select>
<input type="submit" value="Save" id="submit" disabled="disabled"  />

对选定元素进行排序后,如何启用提交?

4

2 回答 2

1

您需要更改 asm 函数,如下所示:

function makeSortable() 
{
    // make any items in the selected list sortable
    // requires jQuery UI sortables, draggables, droppables

    $ol.sortable({
        items: 'li.' + options.listItemClass,
        handle: '.' + options.listItemLabelClass,
        axis: 'y',
        update: function(e, data) 
        {
            var updatedOptionId;

            $(this).children("li").each(function(n) 
            {
                //$option = $('#' + $(this).attr('rel'));
                // i'm not sure what this is here for as the return will break ordering
                //if($(this).is(".ui-sortable-helper")) 
                {
                //   updatedOptionId = $option.attr('id');
                //   return;
                //
                }

                //$original.append($option);
                $original.append($('#' + $(this).attr('rel')));
            });

            //we want to trigger change event always, even if it is only the order that has been changed.
        //if(updatedOptionId) triggerOriginalChange(updatedOptionId, 'sort');
            triggerOriginalChange(updatedOptionId, 'sort');
        }
    }).addClass(options.listSortableClass);
}
于 2011-02-22T15:41:43.557 回答
0

似乎在旧版本的 jquery/jquery-ui 中,为具有 ui-sortable-helper 属性的项目触发了一个附加事件。它

试试我更新的 asmselect 版本。在此处查看代码和示例

于 2012-08-22T12:24:37.997 回答