我有一个打开项目窗口的对话框。我想选择一个项目,单击Add
该项目的 id 附加到一个 div,然后我可以将它提交到数据库。我在警报中获得了 ID,但没有附加任何内容。我想在Add
按钮单击时追加,但只是尝试单击li
也不起作用。
对话框选项
$('.ITA').dialog({
autoOpen: false,
draggable: true,
width: 450,
resizable: false,
dialogClass: "ui-dialog",
modal: true,
show: { effect: 'fade', duration: 200 },
buttons: [{
id: "AddToAddPage",
text: "Send Trade",
click: function () {
// on close the item selected is added to `div ITA`
//$(this).dialog("close");
});
获得<li>
点击并附加到div ITA
$(".ITA").on("click", "li", function () {
//get div
var div = $("#DivToAddTo");
//get id of item
var itemtoadd = $(this).attr("data-id");
alert(itemtoadd);//for debug
//apendTo?
$(itemtoadd).appendTo(div);
});
所选项目应该去的视图
@model IEnumerable<Item>
@{
ViewBag.Title = "Tradepage";
}
<div id="Item">
@foreach (var item in Model)
{
<ul>
<li>
@Html.DisplayFor(modelItem => item.ID)
</li>
<li>
@Html.DisplayFor(modelItem => item.item_name)
</li>
<li>
@Html.DisplayFor(modelItem => item.item_description)
</li>
</ul>
}
</div>
<div id="AddNav">
<a class="AllItemsBtn" href='@Url.Action("GetItemsToAdd")' >Add File...</a>
<a class="SubmitAdds" href="#" >Submit</a>
</div>
<div class = "ITA"></div>
<div id = "AddedItems">Added items go here</div>
查看项目所在的位置
@foreach (var item in Model)
{
<ul>
<li data-id = "@item.ID">
@Html.DisplayFor(modelItem => item.ID)
</li>
<li>
@Html.DisplayFor(modelItem => item.item_name)
</li>
<li>
@Html.DisplayFor(modelItem => item.item_description)
</li>
</ul>
}
<div id="addItemBtn">
<button id="AddToAPage">Add</button>
<p><a id="AddToAdd" href="#">Add</a></p>
</div>