Home > Web Front-end > JS Tutorial > Solutions to IE BUG and string interception substr_Basic knowledge

Solutions to IE BUG and string interception substr_Basic knowledge

WBOY
Release: 2016-05-16 17:37:47
Original
961 people have browsed it

I haven’t paid attention to this problem until now, but I wanted to do something like this today:

Copy code The code is as follows:

var str = 'hello world 8024';

str.substr(-4,4);

Negative numbers count down from the end.

should return: 8024

But I found that in IE6-IE8, the substr parameter does not support negative numbers, and the returned value is: hell. You can test it.


So, we still do not recommend using this substr method.
Let’s use the substring method instead.

For example: str.substring(str.length-4);
will return correctly: 8024

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template