成功后如何删除元素类? [英] How do I remove an element class after success?
问题描述
当用户点击与其图像相关联的表单中的按钮时,我希望图像在成功时消失。我在实现这个方面遇到了麻烦。有什么建议吗?
When the user clicks on a button in the form associated with it's image, I'd like the image to disappear on success. I'm having trouble implementing this. Any advice?
<script type="text/javascript">
$(document).ready(function() {
$(".removebutton").submit(function(event){
event.preventDefault();
$.ajax({
type:"POST",
url:"/munch_video/",
data: {
'video_id': $('.video_id', this).val(), // from form
'playlist': $('.playlist').val(), // from form
'add_remove': $('.add_remove').val(), // from form
},
success: function(message){
alert(message);
$('.span8').removeClass('.video_id', this);
}
});
return false;
});
});
</script>
<div class = "span8" style = "width: 900px;">
<!-- wrapper div -->
<div class='wrapper huluDotCom'>
<!-- image -->
<div class="image" style="position: relative; left: 0; top: 0;">
<a href = "/partners/Business/huluDotCom">
<img src = "/huluDotCom.png">
</a>
<!-- munchbutton div -->
<div class='munchbutton'>
<form method='post' action = '/munch_video/ ' class = 'removebutton'><div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='dKrS8NzqPWFLM6u8wJrAeid4nGw1avGK' /></div>
<input type="hidden" value="Channel" class = "playlist"/>
<input type="hidden" value="huluDotCom" class = "video_id"/>
<input type="hidden" value="remove_video" class = "add_remove"/>
<input type='submit' class="btn btn-danger" value='Remove from plate'/>
</form>
</div>
<!-- end munchbutton div -->
</div>
<!-- end image div -->
</div>
<!-- end wrapper div -->
<!-- wrapper div -->
<div class='wrapper TheEllenShow'>
<!-- image -->
<div class="image" style="position: relative; left: 0; top: 0;">
<a href = "/partners/Business/TheEllenShow">
<img src = "/TheEllenShow.png">
</a>
<!-- munchbutton div -->
<div class='munchbutton'>
<form method='post' action = '/munch_video/ ' class = 'removebutton'><div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='dKrS8NzqPWFLM6u8wJrAeid4nGw1avGK' /></div>
<input type="hidden" value="Channel" class = "playlist"/>
<input type="hidden" value="TheEllenShow" class = "video_id"/>
<input type="hidden" value="remove_video" class = "add_remove"/>
<input type='submit' class="btn btn-danger" value='Remove from plate'/>
</form>
</div>
<!-- end munchbutton div -->
</div>
<!-- end image div -->
</div>
<!-- end wrapper div -->
</div>
推荐答案
首先您的事件的位置.preventDefault();
因为它会停止默认执行。
First your location of event.preventDefault();
Because it will stop stop default excution.
所以它应该只是关于return语句。
So it should be just about the return statement.
其次,你不需要为 removeClass
添加任何其他参数,所以它会像
Second you needn't have to add any other parameter for removeClass
so it will goes like
$this.closest('.image').remove();
其中 $
是保存的参考号。如果 $(this)
Where $this
is a saved ref. if $(this)
第三,我无法找到任何类 span8
以及 video_id
因此,您需要再次提供整个代码或重新检查所有元素。
Third, I could not able to find any element with class span8
as well as video_id
So you need to give whole code or recheck all the elements once again.
最后,还要检查php代码是否给出正确的结果或发送任何错误
Last, also check the out the php code whether it is giving correct result or sending any error
试试这个。
$(".removebutton").submit(function(event){
var $this = $(this);
$.ajax({
type:"POST",
url:"/munch_video/",
data: {
'video_id': $('.video_id', this).val(), // from form
'playlist': $('.playlist').val(), // from form
'add_remove': $('.add_remove').val(), // from form
},
success: function(message){
alert(message);
$this.closest('.image').remove();
}
});
event.preventDefault();
return false;
});
这篇关于成功后如何删除元素类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!