gpt4 book ai didi

jquery - 将 contenteditable span 的长度限制为 5 个数字字符

转载 作者:太空宇宙 更新时间:2023-11-04 13:22:05 25 4
gpt4 key购买 nike

我正在尝试将下面显示的内容可编辑范围限制为仅 5 个字符(4 个数字和一个破折号)。用户需要能够输入从公元前 -9999 年开始的年份。到当前年份 2013。年份之前的破折号表示 B.C.E.年。任何没有破折号的东西都是公元年。

这些都是可以接受的条目:

-9546
-765
-1
0
25
125
2013

<div class="HYPE_element" id="start_year" style="pointer-events: auto; top: 0px; left: 120px; position: absolute; padding: 8px; overflow: visible; word-wrap: break-word; display: inline; z-index: 5; font-size: 16px; color: rgb(120, 204, 187);">
<span contenteditable="true" class="numeric">2013</span>
</div>

现在任何人都可以添加字母数字字符,而且跨度一直向右扩展。

我用它来将字符的长度限制为 5 个。

var content_id = 'start_year';  
max = 4;
//binding keyup/down events on the contenteditable div
$('#'+content_id).keyup(function(e){ check_charcount(content_id, max, e); });
$('#'+content_id).keydown(function(e){ check_charcount(content_id, max, e); });
function check_charcount(content_id, max, e)
{
if(e.which != 8 && $('#'+content_id).text().length > max)
{
// $('#'+content_id).text($('#'+content_id).text().substring(0, max));
e.preventDefault();
}
}

但是我不确定如何将输入的字符限制为数字和破折号。

最佳答案

没有多少浏览器支持这个但是......

<input type="number" max="9999"  min="-9999"/>

关于jquery - 将 contenteditable span 的长度限制为 5 个数字字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15604286/

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