jQuery目标$(window)在特定网页上 [英] jQuery target $(window) on a specific webpage
本文介绍了jQuery目标$(window)在特定网页上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想知道是否有什么简单的方法可以将$(window)定位为仅在localhost/website/hello而不是localhost/website/bye上工作
I'm just wondering if there is any easy way i can target $(window) to only work on localhost/website/hello and not localhost/website/bye
我编写了一个简单的测试脚本,
I've made a easy test script,
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
alert('Hello World');
}
});
问题在于此代码段将在加载脚本的所有页面上正常工作...
The problem is that this snippet will work on all pages where the script is loaded...
推荐答案
首先检查页面路径名,然后应用条件
Check the page path name first and then apply a condition
var url = location.pathname;
if ("url:contains('localhost/website/hello')") {
if ($(window).scrollTop() == $(document).height() - $(window).height()){
alert('Hello World');
}
}
else ("url:contains('localhost/website/bye')") {
//do something else
}
这篇关于jQuery目标$(window)在特定网页上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文