Copy codeThe Code is as follows:
<Script language = javascript>
// The fullwidth space is 12288, And the halfwidth space is 32.
// The Relationship Between the half-width (33-126) of other characters and the full-width (65281-65374) is as follows: the difference is 65248.
// Document. write (65281 ). toString (16) + "----" + (65374 ). toString (16) + "----" + (12288 ). toString (16 ));
String. prototype. dbc2sbc = function ()
{
Return this. replace (/[\ uff01-\ uff5e]/g, function (a) {return String. fromCharCode (. charCodeAt (0)-65248 );}). replace (/\ u3000/g ,"");
}
Document. write ("ABC 123, we are all good friends". dbc2sbc ());
</Script>
Input control
HTML can only be entered in English
Copy codeThe Code is as follows:
<Input type = "text" onfocus = "this. style. imeMode = 'Disabled '"/>
Convert the fullwidth to halfwidth using JS (only numbers are allowed)
HTML
Copy codeThe Code is as follows:
<Input
Onkeypress = "var k = event. keyCode; return k >=48 & k <= 57"
Onpaste = "return! ClipboardData. getData ('text'). match (/\ D /)"
Ondragenter = "return false" style = "ime-mode: Disabled"
>