简体   繁体   English

使用jQuery拖放时如何获取表单控件值

[英]How to get form control values when using jQuery drag and drop

I am creating an asp.net drag and drop application using jQuery. 我正在使用jQuery创建一个asp.net拖放应用程序。 I have got the drag and drop working and communicating with a Windows Service. 我已经拖放工作并与Windows Service通信。 Now, what I need is to be able to pass the text value of what I am dragging as a parameter to the web service. 现在,我需要的是能够将要拖动的文本值作为参数传递给Web服务。 Any ideas where I am going wrong? 有什么想法我要去哪里吗?

I have a repeater control with a literal in it called lbName. 我有一个带有lbName文字的中继器控件。 The ClientIDMode = Inherit with a visibility of false. ClientIDMode =继承,可见性为false。 I need to get the text value of lbName and pass it to the Javascript shown below to be passed on to the web service. 我需要获取lbName的文本值,并将其传递给下面显示的Javascript,以传递给Web服务。

Thanks 谢谢

<li class="col-xs-5 ingredient draggable"><span>
                                                <asp:Literal ID="lbName" Text='<%# Eval("Name") %>' runat="server"></asp:Literal></span></li>

<script>
    $(function () {
        var webMethod = "http://localhost:53809/WebServices/DragDrop.asmx/GetFoodByName";

        $(".draggable").draggable({ helper: "clone" });

        $(".drag-div").droppable({
            accept: ".draggable",
            tolerance: "pointer",
            activeClass: "drop-here",
            hoverClass: "drop-here-hover",

            drop: function (event, ui) {

                $.ajax({
                        type: "POST",
                        url: webMethod,
                        data: "{'FoodName': '" + $(".draggable").find("lbFoodID").val() + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: onSuccess,
                        error: onError
                });
            }
        });

        function onSuccess(data, status) {
            $("#lbFoodNamePopup").html(data.d);

            $.fancybox({
                href: '#add-quantity'
            });
        }
        function onError(request, data, status) {
            alert(request.status);
        }

    });
</script>

see this fiddle 看到这个小提琴

use in drop function : drop功能中使用:

 var text = $(ui.draggable).find("#lblID").text();
 alert(text);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM