Jquery JS Correct comparison of two digital size methods

Source: Internet
Author: User

if (2 > 10)
{
Alert ("Incorrect!");
}

This comparison will not be the desired result: it is equivalent to 2 >1, and the first bit of 10 is taken out to compare.

—————————————————————————————————————————

If there is a need to determine whether the current page entered is greater than the total number of pages, if it is greater then the current page is set to the total number of pages.

Workaround One:

if (eval (pageno) >eval (total))
{
Pageno=total;
}

The eval () function is used to calculate a code string without referencing any particular object.

Workaround Two:

if (pageno*1>total*1)
{
Pageno=total;
}

Workaround Three:

if (pageno-total>0)
{
Pageno=total;
}

Jquery JS Correct comparison of two digital size methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.