在我正在开发的网站上,我们只想在集合/类别的第一页(最多可达 7 页)上显示一些内容。我尝试编写一些 javascript 让它只显示在没有参数的基本 URL 上或仅显示在第一页上,但它对我不起作用。它仍然显示在每个页面上。有人知道我可能会错过什么吗?
$(document).ready(function () {
if((location.search.indexOf('page=')<0)||(location.search.indexOf('page=1')>=0)){
$('div.collection-main').find('div.coll-more-info').css('display','block');
});
最佳答案
更新:-将条件更改为,
if((location.search.indexOf('page=') === -1)||
(location.search.indexOf('page=1') !== -1))
除了语法错误之外,条件看起来不错,
$(document).ready(function () {
if((location.search.indexOf('page=') === -1)||(location.search.indexOf('page=1') !== -1)){
$('div.collection-main').find('div.coll-more-info').css('display','block');
}
});
添加了 }
以关闭 if 循环。
关于javascript - 仅当存在 URL 参数时才显示 HTML 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31414847/