好吧,所以這就是我在當前... 基本上我追加到基於窗口寬度的URL的結尾(使用drawNewUrl()很好地工作)。jQuery - 窗口大小調整事件 - 從URL添加和刪除變量
在窗口調整大小頁面重新加載應該刪除附加屬性我添加在URL('?url/suffix/example /')末尾。但是,它並沒有刪除urlAppend(與jQuery (urlAppend).remove();),它不斷地將urlAppend添加到窗口調整大小的URL的末尾。 (即:example.com/?url/suffix/example/1/?url/suffix/example/1/)。我將如何刪除urlAppend調整大小,並允許繪製新的url?
var urlAppend;
function drawNewUrl() {
if (jQuery(window).width() > 1200) {
var urlAppend = '?url/suffix/example/3/';
} else if (jQuery(window).width() > 768) {
var urlAppend = '??url/suffix/example/2/';
} else {
var urlAppend = '?url/suffix/example/1/';
}
jQuery('.class').attr('href', function() {
return this.href + urlAppend;
});
}
jQuery(window).resize(function() {
jQuery(urlAppend).remove();
drawNewUrl();
});
jQuery(document).ready(function() {
drawNewUrl(); // for onload
});
'urlAppend = '''而不是'的jQuery(urlAppend)卸下襬臂()'? – kasperite
@kasperite Hmmmm ...這將無法用於從url中刪除屬性..僅用於重置變量 –