Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

javascript - JSLint说“缺少基数参数”(JSLint says “missing radix parameter”)

I ran JSLint on this JavaScript code and it said:(我在此JavaScript代码上运行了JSLint,它说:)

Problem at line 32 character 30: Missing radix parameter.(第32行的字符30处的问题:基数参数丢失。)

This is the code in question:(这是有问题的代码:)

imageIndex = parseInt(id.substring(id.length - 1))-1;

What is wrong here?(怎么了)

  ask by Mike Vierwind translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It always a good practice to pass radix with parseInt -(用parseInt传递基数始终是一个好习惯-)

parseInt(string, radix)

For decimal -(对于小数-)

parseInt(id.substring(id.length - 1), 10)

If the radix parameter is omitted, JavaScript assumes the following:(如果省略了radix参数,则JavaScript假定以下内容:)

  • If the string begins with "0x", the radix is 16 (hexadecimal)(如果字符串以“ 0x”开头,则基数为16(十六进制))
  • If the string begins with "0", the radix is 8 (octal).(如果字符串以“ 0”开头,则基数为8(八进制)。) This feature is deprecated(不推荐使用此功能)
  • If the string begins with any other value, the radix is 10 (decimal)(如果字符串以任何其他值开头,则基数为10(十进制))

( Reference )(( 参考 ))


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...