jquery asmselect:更改不会在排序时触发
我使用 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" />
如何在选定的元素排序时启用提交?
I'm using the asmselect plugin to allow users to select & order multiple items from a select box.
I only want to enable the submit button when the user has made a change. The following works, but change does not get called when sorting the selected elements:
<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>
The select & submit:
<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" />
How can I enable the submit when selected elements are sorted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要更改 asm 函数,如下所示:
You need to change asm function as below:
似乎在旧版本的 jquery/jquery-ui 中,具有 ui-sortable-helper 属性的项目会触发一个附加事件。尝试
我更新版本的 asmselect。 在此处查看代码和示例
It seems that with older versions of jquery/jquery-ui, an additional event was triggered for an item with ui-sortable-helper attribute. It
Try my updated version of asmselect. See code and example here