gpt4 book ai didi

javascript - 使用javascript在keypressevent上将小写转换为大写

转载 作者:行者123 更新时间:2023-12-02 19:01:24 25 4
gpt4 key购买 nike

当触发 onkeypress 事件时,如何在输入小写字母时转换大写字母?我的函数可以在 Internet Explorer 中运行,但不能在 Google Chrome 和 FireFox 中运行。

function Capital(evt) [
key = (evt || window.event) ? evt.keyCode : evt.which;
if (key >= 97 && key <= 122) {
if ((evt || window.event)) evt.keyCode = evt.keyCode - 32;
else evt.which = evt.which - 32;
}
}

此函数在 onkeypress="Capital(event)"

中调用

最佳答案

这根本不需要 JS,只需为您的元素设置 text-transform: uppercase; 即可。

关于javascript - 使用javascript在keypressevent上将小写转换为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14766547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com