$(location).attr('href'); not working

后端 未结 6 1289
醉梦人生
醉梦人生 2021-01-28 23:22

I do not know why but I have problems with this code. The banner is displayed on every page although it has specified the attribute $(location).attr(\'href\') you can help me?:<

6条回答
  •  無奈伤痛
    2021-01-28 23:39

    Don't you mean just location.href?

    This is assuming you are talking about window.location and not something else.

    Returns a Location object, which contains information about the URL of the document and provides methods for changing that URL. You can also assign to this property to load another URL.

    Location is not an element in the dom thus jQuery can not select it.

    So your code would be like so:

    var currentUrl = window.location.href;
    

提交回复
热议问题