Get the App
SLTechnology News&Howtos  ›  Development  › 

The method of comparing Chinese characters in jquery

Shulou Source: shulou.com Published: 2022-06-01 07:35:42 10月28日 Update

This article introduces the relevant knowledge of "jquery's method of comparing Chinese characters". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

In fact, you use js to convert strings to numbers in jquery, because jquery itself is written in js encapsulation.

For example, when we use ajax in jquery to update the number of times or popularity of an article, we need to use the function of converting strings to numbers.

Let's first take a look at the function commands in JS that convert strings to numbers:

1:parseInt (string)? The function of this function is to parse from the beginning of string and return an integer, which is quite general. Let's take a look at a few examples and you will understand:

ParseInt ("1234blue"); / / returns 1234

ParseInt ("123"); / / returns 123

ParseInt ("22.5"); / / returns 22

ParseInt ("blue"); / / returns NaN

/ / in addition, the parseInt () method has a base mode, which converts a binary, octal, hexadecimal, or any other string to an integer. The base is specified by the second parameter of the parseInt () method. The example is as follows:

ParseInt ("AF", 16); / / returns 175

ParseInt ("10", 2); / / returns 2

ParseInt ("10", 8); / / returns 8

ParseInt ("10", 10); / / returns 10

If the decimal number contains a leading 0, it is best to use the cardinality of 10 so that you do not accidentally get an octal value. For example:

ParseInt ("010") / / returns 8

ParseInt ("010", 8); / / returns 8

ParseInt ("010", 10); / / returns 10

2:parseFloat (): this function is handled in a similar way to the parseInt () method.

Another difference in using the parseFloat () method is that the string must represent a floating-point number in decimal form, and parseFloat () has no base pattern.

ParseFloat ("1234blue"); / / returns 1234.0

ParseFloat ("0xA"); / / returns NaN

ParseFloat ("22.5"); / / returns 22.5

ParseFloat ("22.34.5"); / / returns 22.34

ParseFloat ("0908"); / / returns 908

ParseFloat ("blue"); / / returns NaN

3:Number (): casts the type, similar to the parseInt () and parseFloat () methods, except that it converts the entire value, not part of it.

Number (false) 0

Number (true) 1

Number (undefined) NaN

Number (null) 0

Number ("5.5") 5.5

Number ("56") 56

Number ("5.6.7") NaN

Number (new Object ()) NaN

Number (100) 100

There is a summing js here.

Event

Function count () {

Var res=0

/ / get the value of the first input box

Var firnum=parseInt (document.getElementById ("txt1"). Value)

/ / get the value of the second input box

Var secnum=parseInt (document.getElementById ("txt2"). Value)

/ / get the value of the selection box

Var sel=document.getElementById ("select"). Value

This is the end of the content of "jquery's method of comparing Chinese characters". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Characters methods strings functions numbers Chinese similar octal content function decimal that is integers articles ways more patterns knowledge decimal processing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB OPPO Reno Microsoft Shulou Information