gpt4 book ai didi

c# - 将 div 移动到另一个 div (ASP.NET MVC)

转载 作者:行者123 更新时间:2023-11-27 23:17:32 24 4
gpt4 key购买 nike

我正在编写 ASP.NET 应用程序

我有一个div,这是代码:

<div class="title" style="margin-top:15px;margin-left:15px;">
<img class="click" src="@Url.Content(" ~/Images/plus_plus.png")" />
<span>
@Html.TextBoxFor(modelItem => item.question, new {@class="testclass", @readonly = "readonly" })
</span>

<a class="click2" style="margin-left:10px;">
<img src='@Url.Content("~/Images/arrow.png")' />
</a>
<a style="margin-left:25px;" href='@Url.Action("Edit", "Questions", new {id = item.QuestionId})'>
<img src='@Url.Content("~/Images/Edit.png")' />
</a>
<a href='@Url.Action("Delete", "Questions", new {id = item.QuestionId})'>
<img src='@Url.Content("~/Images/Delete.png")' />
</a>
</div>

我需要将它移到另一个。这是代码:

 <div class="title2"></div>

据我了解,它需要通过 jquery 完成。

我试着写这个脚本

 <script type="text/javascript" >
$('.title').on('click', function () {
$(this).next().toggle();
});
$('click2').click(function () {
var elem = $(this).closest('.title');
elem.hide();
$('title2').append(elem).show();
elem.remove();
});
</script>

但它不起作用。我的问题在哪里?

最佳答案

删除 .hide并附加 html你的elemtitle2

var elem = $(this).closest('.title');
$('.title2').append($(elem).html()).show();
$('.title').remove()

我添加了一些 <hr>并删除你们中的一些 mvc 代码,以使示例正常工作。它不会给您带来任何问题。

$('.title').on('click', function() {
$(this).next().toggle();
});
$('.click2').click(function() {
var elem = $(this).closest('.title');
$('.title2').append($(elem).html()).show();
$('.title').remove()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="title" style="margin-top:15px;margin-left:15px;">
<img class="click" src="@Url.Content(" ~/Images/plus_plus.png ")" />
<span>
</span>

<a class="click2" style="margin-left:10px;">
<img src='@Url.Content("~/Images/arrow.png")' />
</a>

</div>
<hr>
<hr>
<div class="title2"></div>

关于c# - 将 div 移动到另一个 div (ASP.NET MVC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42488320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com