使代码有条件jquery
好的,我正在开发网站的新版本: http://themes.visualise.ca/visualise/
当您通过单击图像选择项目时,它会在现有页面中动态加载请求的 WordPress 项目页面,并更改 url 以包含哈希值,这样我就得到: http://themes.visualise.ca/visualise/#project
如果我将此直接 url 提供给人们,Wordpress 会自动加载项目页面,就好像用户单击了其中的图像一样页面。
一切都如我所愿,除了一件事之外,即使网址中没有 #project 哈希,我的代码也会使项目页面(“#board”)始终加载,所以我想让代码成为有条件的。
$(window).load(function(e){
$.ajaxSetup({cache:false});
var post_slug = window.location.hash.substring(1);
$("#board").load("http://themes.visualise.ca/visualise/ajax/",{slug:post_slug});
$("#board").delay(1500).slideDown("slow");
});
http://url , http://url , http:// /url/ , http://url/# , http://url/#/ 不应仅加载项目板 http://url/#项目 或 http://url/#whatever 应该
但我不知道如何,因为我仍然jQuery 和一般编程新手。
OK I'm working on the new version of my website: http://themes.visualise.ca/visualise/
When you select a project by clicking on an image it dynamically loads the requested wordpress project page within the existing page and changes the url to include the hash so I get: http://themes.visualise.ca/visualise/#project
And if I give this direct url to people Wordpress automatically load the project page as if the user had clicked on the image within the page.
Everything is as I want it except for one thing my code make the project page ("#board") loads all the time even if there is no #project hash in the url so I would like to make the code conditional.
$(window).load(function(e){
$.ajaxSetup({cache:false});
var post_slug = window.location.hash.substring(1);
$("#board").load("http://themes.visualise.ca/visualise/ajax/",{slug:post_slug});
$("#board").delay(1500).slideDown("slow");
});
http://url , http://url/ , http://url/# , http://url/#/ should not load the project board only http://url/#project or http://url/#whatever should
But I don't know how since I still new to jQuery and programming in general.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它应该是这样的:
我们询问是否存在字符串哈希。
编辑:我已更新条件以使用正则表达式来满足您最近评论的需求
希望这有帮助
It should be like this:
We are asking if there's a string hash.
EDIT: I've updated the condition to use a regular expression to suite the needs you recently commented
Hope this helps