简体   繁体   English

使大写锁定在页面加载上

[英]Make Caps Lock on page Load

How to make CAPSLOCK TurnOn Automatically on page, when capslock is OFF , 当capslock为OFF时,如何使CAPSLOCK自动打开页面,

Using Javascript 使用JavaScript

You cannot manipulate the caps lock state in javascript. 您无法在javascript中操作大写锁定状态。

In general, you cannot simulate any keypress, except on the page itself. 通常,除了页面本身之外,您无法模拟任何按键。 Javascript is in general sandboxed so that no website can affect anything else. Javascript通常处于沙盒状态,因此没有网站可以影响其他任何内容。 Allowing it to send keypresses would allow all sorts of havoc to occur. 允许它发送按键将导致各种破坏。

Why not use CSS to force the text to upper-case-case (and then make sure it's upper-case when you come to process the form)? 为什么不使用CSS强制文本大写(然后在处理表单时确保大写)? this question explains how to do it with CSS and JavaScript too. 这个问题也说明了如何使用CSS和JavaScript。

Have you considered capturing the keyUp event and converting all alphabetic characters to caps if they are not? 您是否考虑过捕获keyUp事件并将所有字母字符转换为大写字母(如果不是)? Assign something like the following function to the onkeyup event of whatever fields you care about (code is from liewcf.com ): 将以下函数分配给您关心的任何字段的onkeyup事件(代码来自liewcf.com ):

function uppercase() {
    key = window.event.keyCode;
    if ((key > 0x60) && (key < 0x7B)) {
        window.event.keyCode = key-0x20;
    }
}

如果不使用外部库,则无法使用Javascript修改客户端系统设置。

我不认为可以,但是为什么不使用CSS属性“ text-transform”设置为“ capitalize”呢?

You can't, and shouldn't. 您不能,也不应该。

What you can do is have your input elements convert text typed in mixed case to upper case, as the text is typed or afterward. 可以做的是,让您的输入元素将输入时使用大小写混合的文本转换为大写,然后再键入。

I'm afraid you can't simulate key pressing in JavaScript it would be security hole. 恐怕您无法模拟JavaScript中的按键操作,这将是安全漏洞。 But you still can detect if caps lock is enabled. 但是您仍然可以检测是否启用了大写锁定。 Found an example . 找到一个例子

只需设置CSS样式的text-transform: capitalize并在处理表单数据时将文本通过一些大写功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM