javascript - 在 Asp.Net 中拖放 2 个列表框

标签 javascript jquery asp.net asp.net-ajax

我想在 Asp.Net 的 2 个列表/组合框中实现拖放功能。我将从列表框 1 中选择并拖动 1 个项目并将其放到列表框 2 上。那么我应该如何开始呢?

是否有可用的 Jquery 插件?

感谢

里克· jackson

最佳答案

网上有很多可用的插件,但您可以使用 java 脚本来实现。我在 asp.net 中创建了一个示例应用程序。看看这个,如果您有任何疑问,请告诉我。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ST.aspx.cs" Inherits="ST" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        var d;
        function drag(objSource) {
            this.select = objSource;
        }

        function drag.prototype.drop(objDest) {
            if (!this.dragStart) return;
            this.dest = objDest;

            var o = this.option.cloneNode(true);
            this.dest.appendChild(o);
            this.select.removeChild(this.option);
        }

        function drag.prototype.setIndex() {
            var i = this.select.selectedIndex;

            //i returns -1 if no option is "truly" selected
            window.status = "selectedIndex = " + i;
            if (i == -1) return;

            this.option = this.select.options[i];
            this.dragStart = true;
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ListBox ID="one" runat="server" onmousedown="d = new drag(this);" onmouseup="d.drop(this.form.two);"
            onmouseout="if (typeof d != 'undefined') d.setIndex();">
            <asp:ListItem Text="Opt1" Value="1"></asp:ListItem>
            <asp:ListItem Text="Opt2" Value="2"></asp:ListItem>
            <asp:ListItem Text="Opt3" Value="3"></asp:ListItem>
        </asp:ListBox>
        <asp:ListBox ID="two" runat="server">
            <asp:ListItem Text="Opt1" Value="1"></asp:ListItem>
            <asp:ListItem Text="Opt2" Value="2"></asp:ListItem>
            <asp:ListItem Text="Opt3" Value="3"></asp:ListItem>
        </asp:ListBox>
    </div>
    </form>
</body>
</html>

关于javascript - 在 Asp.Net 中拖放 2 个列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5886469/

相关文章:

javascript - 识别两个文本中的单词(for循环中的if语句)

javascript - ENOENT : no such file or directory, 打开 'Filename'

c# - 如何使用参数从 Access 数据库中保存数字?

asp.net - 只使用一次的功能应该放在 UserControl 中吗?

jquery - 删除元素时出现问题

asp.net - 使用 jqGrid 和 asp.net web 表单(免费版)

javascript - extjs 全局处理 http 响应

javascript - 在 Jest 测试中将通用数据放在哪里

javascript - SQL 没有 PHP 只有 javascript

jquery - AJAX 成功 html 对话框,不会在按钮单击时关闭