.substring error: “is not a function”

后端 未结 4 1409
执笔经年
执笔经年 2020-12-30 19:34

I don\'t understand why I get an error message using the substring method to declare a variable.

I want to use the first part of the URL in a comparison.

Sit

相关标签:
4条回答
  • 2020-12-30 19:48

    You can use substr

    for example:

    new Date().getFullYear().toString().substr(-2)
    
    0 讨论(0)
  • 2020-12-30 19:50

    you can also quote string

    ''+document.location+''.substring(2,3);
    
    0 讨论(0)
  • 2020-12-30 20:00

    try this code below :

    var currentLocation = document.location;
    muzLoc = String(currentLocation).substring(0,45);
    prodLoc = String(currentLocation).substring(0,48); 
    techLoc = String(currentLocation).substring(0,47);
    
    0 讨论(0)
  • 2020-12-30 20:01

    document.location is an object, not a string. It returns (by default) the full path, but it actually holds more info than that.

    Shortcut for solution: document.location.toString().substring(2,3);

    Or use document.location.href or window.location.href

    0 讨论(0)
提交回复
热议问题