jquery hide this.parent似乎隐藏了所有内容
我正在使用asp.net核心剃须刀引擎。我根据数据库中的行数填充html。我正在使用ajax从数据库中删除项目。它可以工作,但我不知道如何隐藏刚刚删除的数据。当我使用jquery hide this.parent似乎隐藏了所有内容,jquery,html,asp.net,Jquery,Html,Asp.net,我正在使用asp.net核心剃须刀引擎。我根据数据库中的行数填充html。我正在使用ajax从数据库中删除项目。它可以工作,但我不知道如何隐藏刚刚删除的数据。当我使用$(this.hide()时,它会隐藏删除按钮。当我尝试$(this).parent().hide()时,我的所有数据都被隐藏 这是我的密码 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery
$(this.hide()
时,它会隐藏删除按钮。当我尝试$(this).parent().hide()
时,我的所有数据都被隐藏
这是我的密码
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.update').click(function(){
$(this).parent().submit(function(event){
event.preventDefault();
var $form = $( this );
url = $( this ).attr( "action" );
term = $form.find( "textarea[name='Description']" ).val();
var posting = $.post( url, { Description: term } );
});
});
$('.delete').click(function(){ //This is my delete function
$(this).parent().submit(function(event){
event.preventDefault();
var $form = $( this );
url = $form.attr( "action" );
var posting = $.post( url );
$(this).parent().hide();
});
});
$('button').click(function(){
$('#New_Note').submit(function(event){
event.preventDefault();
var $form = $( this );
url = $form.attr( "action" );
term = $form.find( "input[name='Note']" ).val();
console.log(term);
var posting = $.post( url, { Note: term } );
posting.done(function( data ) {
var content = $( data ).find( "#content" );
console.log(content);
// <!--$( "div" ).append( term );-->
var r= $('<p>term</p>');
});
});
});
});
</script>
@model ajaxNotes.Models.Home
<div class = "notes">
@{
if(ViewBag.Notes != null)
{
foreach(var note in ViewBag.Notes )
{
<p>@note.Note</p>
<form action="/delete/@note.Id" method="post" id="delete_note">
<input type="submit" name="submit" value="Delete" class='delete'/>
</form>
<form action="/AddDescription/@note.Id" method="post" class="update_note">
<label asp-for="Description" ></label>
<textarea name="Description" id="" cols="30" rows="10" class="Description">@note.Description</textarea>
<input type="submit" name="submit" class="update" value="Update"/>
</form>
}
}
}
</div>
<form asp-controller="Home" asp-action="AddNote" method="post" id="New_Note">
<label asp-for="Note" ></label>
<p><input asp-for="Note" class = "Note" name="Note"/> </p>
@{
if(ViewData["error"] != null)
{
<p>Please enter data for Notes</p>
}
}
<button type="submit">Add Note</button>
</form>
$(文档).ready(函数(){
$('.update')。单击(函数(){
$(this).parent().submit(函数(事件){
event.preventDefault();
var$form=$(此);
url=$(this.attr(“操作”);
term=$form.find(“textarea[name='Description']”)val();
var posting=$.post(url,{Description:term});
});
});
$('.delete')。单击(函数(){//这是我的删除函数
$(this).parent().submit(函数(事件){
event.preventDefault();
var$form=$(此);
url=$form.attr(“操作”);
var posting=$.post(url);
$(this.parent().hide();
});
});
$(“按钮”)。单击(函数(){
$('New#Note')。提交(函数(事件){
event.preventDefault();
var$form=$(此);
url=$form.attr(“操作”);
term=$form.find(“输入[name='Note']”).val();
控制台日志(术语);
var posting=$.post(url,{注:term});
过帐.完成(功能(数据){
var content=$(数据)。查找(#content);
控制台日志(内容);
//
var r=$('期限');
});
});
});
});
@型号ajaxNotes.Models.Home
@{
如果(ViewBag.Notes!=null)
{
foreach(ViewBag.Notes中的var注释)
{
@注意,注意
@注.说明
}
}
}
@{
如果(ViewData[“错误”]!=null)
{
请为注释输入数据
}
}
添加注释
这是我按下删除按钮之前的图像
在我按下删除按钮之后。
而不是使查询复杂化。在每个音符周围添加一个
div
例如:
<div class="notes">
@{ if(ViewBag.Notes != null) { foreach(var note in ViewBag.Notes ) {
<div>
<p>@note.Note</p>
<form action="/delete/@note.Id" method="post" id="delete_note">
<input type="submit" name="submit" value="Delete" class='delete' />
</form>
<form action="/AddDescription/@note.Id" method="post" class="update_note">
<label asp-for="Description"></label>
<textarea name="Description" id="" cols="30" rows="10" class="Description">@note.Description</textarea>
<input type="submit" name="submit" class="update" value="Update" />
</form>
</div>
} } }
</div>
这将带来未来的灵活性。我建议只添加一个包含每个块的div并删除它,而不是使查询复杂化。这将导致该领域的灵活性future@A.J谢谢张贴你的答案,这样我可以给你信用
$(this).parent().hide();