jquery: if url contains #work then do something

后端 未结 2 1966
南方客
南方客 2020-12-14 08:52

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 = windo         


        
相关标签:
2条回答
  • 2020-12-14 09:08

    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 讨论(0)
  • 2020-12-14 09:17
    $(function() {
        if ( document.location.href.indexOf('#Work') > -1 ) {
            $('#elementID').animate({"left": "250"}, "slow");
        }
    });
    
    0 讨论(0)
提交回复
热议问题