我想定位是否存在某个哈希值,例如。 #nameofthehash
,在 URL 中,然后使用我的代码执行操作。但它不仅需要检查 URL 是否包含 #nameofthehash
,还需要检查是否单击了页面上的按钮之一。如果完成,则需要运行代码。
代码无需第二行即可运行。我只是不知道如何正确实现第二行。
$('a[href="#groeien"]').click(function(),
$(location.hash).contains("#groeien") {
$(".active").removeClass("active");
$(this).parent('.label').addClass("active");
$('#groeien').slideDown(1000);
$('#ontdekken').slideUp(1000);
$('#ondernemen').slideUp(1000);
$('#spelen').slideUp(1000);
});
提前致谢!
更新:我创建了一个jsfiddle来显示当前情况,http://jsfiddle.net/qeDam/3/
最佳答案
尝试使用:
$('a[href="#groeien"]').click(function () {
if(window.location.hash.indexOf("#groeien") > -1) {
$(".active").removeClass("active");
$(this).parent('.label').addClass("active");
$('#groeien').slideDown(1000);
$('#ontdekken').slideUp(1000);
$('#ondernemen').slideUp(1000);
$('#spelen').slideUp(1000);
}
});
关于javascript - URL 中的某些哈希值与页面点击事件相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23381441/