我正在使用AJAX获得元素,但是现在,我只想在函数“ click”中将其删除,但是它不起作用,我的页面正在更改。
这是我的代码,我正在尝试使用“ hide”或“ fadeOut”将其删除。我到底该怎么做?
$(function(){
$('#send__mail').on('click', function(e){
e.preventDefault();
$('.mail').fadeIn('fast');
var email = $(this).attr('href');
$.ajax({
url:email,
type:'GET',
success:function(html){
$('.mail__content').html(html);
}
});
});
});
[不确定您的“我的页面正在改变”的意思,也不清楚要在处理程序中隐藏的内容。猜测您正在尝试隐藏使用给定处理程序发送电子邮件的按钮,只需对其进行以下更改,就应该隐藏该按钮。
尝试:
$(function(){
$('#send__mail').on('click', function(e){
e.preventDefault();
$('.mail').fadeIn('fast');
var email = $(this).attr('href');
$.ajax({
url:email,
type:'GET',
success:function(html){
$('.mail__content').html(html);
}
});
$(this).hide(); //this will hide the button that triggered this click handler
});