gpt4 book ai didi

javascript - 将小型大写字母替换为所有大写字母文本

转载 作者:行者123 更新时间:2023-11-30 07:43:15 24 4
gpt4 key购买 nike

我无法将文本框中的所有小写字母转换为大写字母:

<body>
<input type="text" id="input_1" class="allcaps"/>
<input type="text" id="input_2" class="allcaps"/>
</body>

$(document).ready(function () {

//trigger ng event

$('.alcaps').live("keyup", function () {
var fin = $('.alcaps').val();
$('.alcaps').val(fin.toUpperCase());
});
});

第一个输入框将其内容转换为大写,但我放入第一个框中的文本也被复制到第二个输入框...

最佳答案

当使用类作为选择器时,您将选择具有该类的所有输入框并将值设置为与第一个相同。使用 this 关键字仅定位当前文本框:

$(document).ready(function() {
$(document).on('keyup', '.alcaps', function() {
var fin = this.value;
this.value = fin.toUpperCase();
});
});​

FIDDLE

关于javascript - 将小型大写字母替换为所有大写字母文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12154848/

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