Javascript 将小大写替换为所有大写文字
我无法将文本框中的所有小写转换为大写:Javascript 将小大写替换为所有大写文字,javascript,jquery,Javascript,Jquery,我无法将文本框中的所有小写转换为大写: <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("ke
<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());
});
});
$(文档).ready(函数(){
//触发ng事件
$('.alcaps').live(“键控”,函数(){
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();
});
});
当使用类作为选择器时,选择该类的所有输入框,并将值设置为与第一个相同。使用
this
关键字仅针对当前文本框:
$(document).ready(function() {
$(document).on('keyup', '.alcaps', function() {
var fin = this.value;
this.value = fin.toUpperCase();
});
});
用户
处理程序内的此
:
$('.alcaps').live("keyup", function () {
var fin = $(this).val();
$(this).val(fin.toUpperCase());
});
用户
此处理程序中的:
$('.alcaps').live("keyup", function () {
var fin = $(this).val();
$(this).val(fin.toUpperCase());
});
您可以使用引用当前输入的此
,还请注意,如果live
不推荐使用,您可以在
上使用:
$(document).on("keyup", ".alcaps", function () {
this.value = this.value.toUpperCase()
});
您可以使用引用当前输入的此
,还请注意,如果live
不推荐使用,您可以在
上使用:
$(document).on("keyup", ".alcaps", function () {
this.value = this.value.toUpperCase()
});
我得到了$('.smallcaps').live(“keyup”,function(){var fin=$(this.val();$(this.val());输入是用javascript动态插入的吗?如果不是,就没有理由使用live()
,在大多数情况下,你不应该使用live()
,因为它已被弃用,并被替换为on()
。是的,它们是动态插入的。对于on()的东西,我在jquery中仍然是新的。我得到了$('.smallcaps').live(“keyup”,function(){var fin=$(this.val();$(this.val)(fin.toLowerCase());输入是用javascript动态插入的吗?如果不是,就没有理由使用live()
,而且在大多数情况下,您根本不应该使用live()
,因为它已被弃用,并已被on()
替换。是的,它们是动态插入的。.tnx对于on()东西,我在jquery中仍然是新的。$(文档)。ready(函数(){//trigger ng event$('.alcaps').live(“keyup”,函数(){var fin=$(this.val();$(this.val)(fin.toUpperCase();});$('.smallcaps').live(“keyup”,函数(){var fin=$(this).val();$(this.val(fin.toLowerCase();});$(document).ready(函数(){//trigger ng event$('.alcaps').live(“keyup”,函数(){var fin=$(this.val());$(this.val(fin.toUpperCase());});$('.smallcaps').live(“keyup”,函数(){var-fin=$(this.val();$(this.val(fin.toLowerCase());});});