开发者

jquery: if url contains #work then do something

开发者 https://www.devze.com 2023-02-27 20:39 出处:网络
I tried to write a script which allow me to load certain events when I enter specific url. My code looks like this:

I tried to write a script which allow me to load certain events when I enter specific url.

My code looks like this:

$(function(){
    var url = window.location.pathname;
    $("url:contai开发者_如何学JAVAns('#Work')").animate({"left": "250"}, "slow");
});

But it doesnt work. Any suggestions? Any help is appreciated.


$(function() {
    if ( document.location.href.indexOf('#Work') > -1 ) {
        $('#elementID').animate({"left": "250"}, "slow");
    }
});


window.location.href is pulling the URL into a variable, so you can't search for #Work using that method. Try:

var url = window.location.href;

if (url.search("#Work") >= 0) {
    //found it, now do something
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消