I store some parameters client-side in HTML and then need to compare them as integers. Unfortunately I have come across a serious bug that I cannot explain. The bug seems to be that my JS reads parameters as strings rather than integers, causing my integer comparisons to fail.
I have generated a small example of the error, which I also can't explain. The following returns 'true' when run:
javascript:alert("2">"10")
Best Answer-推荐答案
Parse the string into an integer using parseInt :
javascript:alert(parseInt("2", 10)>parseInt("10", 10))
|