我一直試圖從下面的一次點擊函數中刪除這個#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);
}
}
});
});
任何幫助,將不勝感激:)
如果這不只是使用'。對()',而不是'。一()'...請編輯您的問題。你的問題可以更好地定義。你期望的*幫助*是什麼? –