gpt4 book ai didi

javascript - keyup 功能不起作用

转载 作者:行者123 更新时间:2023-12-03 01:40:24 27 4
gpt4 key购买 nike

我正在 js 中制作字符计数器,但 keyup 事件不起作用???

$(document).ready(function() {
function countingCharacter(element, maxCount) {
var countLength = $('#' + element).val().length();
alert(countLength);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea onkeyup="countingCharacter("storyOutline",100)" onkeypress="countingCharacter("storyOutline",100);" onkeydown="countingCharacter("storyOutline",100)" id="storyOutline" rows="5" class="form-control" name="labinput7" placeholder="Story Outline" required></textarea>

最佳答案

为了避免与函数范围相关的任何问题并使 JS 代码与 HTML 分离,我将使用以下事件绑定(bind):

$('#storyOutline').on('keyUp', function() {
var length = $(this).val().length();
alert(length);
});

关于javascript - keyup 功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50873646/

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