我一直试图从下面的一次点击函数中删除这个#static
id,并使用变量自动获取像'#static
,#dynamic
...等等,并把它放在一键功能。这将通过改变它的ID名称来节省我一次又一次的复制和粘贴相同的功能。此外,这也将使代码看起来很简洁&。如何获取点击元素的ID并存储在变量中,并在使AJAX调用的函数中使用它
jQuery(document).ready(function($){
// Home Page Static Portfolio Ajax Query
$(this).one('click', '#static', function(e){
var that = $(this);
var id = that.attr('id');
var rel = that.data('rel');
var ajaxurl = that.data('url');
$.ajax({
url : ajaxurl,
type : 'POST',
data : {
rel : rel,
action : 'home_filter_' + id + '_portfolios'
},
error : function(response){
console.log(response);
},
success : function (response){
if (response == '') {
$('figure' + id).after('<div class="end_of_testimonial"><h3>You have reached the end of the line</h3><p>No more portfolios to load!</p></div>');
} else {
$('.gallery-wrapper').append(response);
}
}
});
});
任何帮助,将不胜感激:)
如果这不只是使用'。对()',而不是'。一()'...请编辑您的问题。你的问题可以更好地定义。你期望的*帮助*是什么? –