gpt4 book ai didi

jquery - 如何使用 jQuery 获取所选文本的字符长度?

转载 作者:行者123 更新时间:2023-12-01 00:56:57 24 4
gpt4 key购买 nike

我需要在 id="message"的文本区域中选择一些文本,然后获取其字符数。

我假设需要 .length() 的东西,但我不确定实际获取所选文本需要什么,然后用它来确定它的长度。

提前致谢

最佳答案

我认为你正在为此努力

$("#message").text().length;

编辑:

$("button").click(function(){
var txt=document.getElementById("message");
alert(txt.value.substr(txt.selectionStart, (txt.selectionEnd -txt.selectionStart)).length);
});

关于jquery - 如何使用 jQuery 获取所选文本的字符长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17673420/

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