Home > Web Front-end > JS Tutorial > Summary of some restrictive controls on text boxes~~_Form special effects

Summary of some restrictive controls on text boxes~~_Form special effects

WBOY
Release: 2016-05-16 18:29:25
Original
896 people have browsed it
1. Restrict the text box from inputting Chinese:
In the past, I often used judgment to write, such as:
Copy code The code is as follows:

function nocn(obj)
{
for(i=0;i{
var c = document.getElementsByName("Text1")[0].value.substr(i,1);
var ts = escape(c);
if(ts.substring(0,2) == "%u")
{
document.getElementsByName("Text1")[0].value = "";
alert("Not possible here Enter Chinese/full-width characters");
}
}
}


But few people use ime-mode:disabled (implemented with css Close the text box input method)
ime-mode
Syntax:
ime-mode: auto | active | inactive | disabled
Value:
auto: Default value. Does not affect the status of IME. The same as when the ime-mode attribute is not specified
active: specifies all characters entered using IME. That is to activate the local language input method. The user can still deactivate the IME
inactive : Specifies all characters that are not entered using the IME. That is to activate non-native languages. The user can still deactivate the IME
disabled : Disable the IME completely. For focused controls (such as input boxes), the user cannot activate the IME

Then:

ime-mode:disabled is to disable the input method.
Extension:
Copy code The code is as follows:





Think about it yourself~
2. .Restrict the text box from pasting:
Generally when we see this, we will have this idea: disable the Ctrl key and C key, and then disable the right click, you can perfectly disable the paste function.
Then you need to write a JS file (this JS file has relevant content on this blog)
In fact, onpaste="return false;" can perfectly disable pasting, and be aware that it disables pasting. function, so using this attribute, the user cannot paste content even if the right click is not disabled.

Then:
Copy code The code is as follows:



onpaste is disabled for pasting.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template