客户端字符数 - 文本框 [英] Client side character count - Textbox

查看:84
本文介绍了客户端字符数 - 文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将文本框输入限制为500个字符时,我想在用户输入文本框时包含一个

动态字符输入。

这显然是一个客户端控件,可能是一个自定义验证器

,带有一个用javascript编写的函数。

有没有人这样做过?有人有例子吗?


问候

In limiting textbox input to 500 characters I would like to include a
dynamic count of characters input while the user is typing into a textbox.
This would obviously be a client side control, possibly a custom validator
with a function written in javascript.
Has anyone done this? Does someone have an example?

Regards

推荐答案

在JavaScript中,你可以使用的长度属性

文本框的value属性来获取字符数。将事件处理程序连接到

" onchange"文本框的属性,如下所示:


< script type =" text / javascript"><! -

function countChar(str )

{

window.status = str.length +"字符类型;

}

// - >< / script>

< input type =" text"名称= QUOT; MYTEXT" onchange =" countChar(this.value)">


-

HTH,

Kevin Spencer

..Net开发人员

微软MVP

大件物品组成

很多小东西。

Jerry <济********* @ yahoo.com>在消息中写道

新闻:#g ************** @ TK2MSFTNGP12.phx.gbl ...
In JavaScript, you can use the length property of the value property of the
textbox to get the number of characters. Wire your Event Handler to the
"onchange" property of the textbox, like so:

<script type="text/javascript"><!--
function countChar(str)
{
window.status= str.length + " characters typed";
}
// --></script>
<input type="text" name="MyText" onchange="countChar(this.value)">

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Jerry" <Je*********@yahoo.com> wrote in message
news:#g**************@TK2MSFTNGP12.phx.gbl...
限制文本框输入我希望在用户输入文本框时包含一个动态的字符输入数量。
这显然是一个客户端控件,可能是一个自定义验证器
用javascript编写的函数。
有没有人这样做过?有人有例子吗?

问候
In limiting textbox input to 500 characters I would like to include a
dynamic count of characters input while the user is typing into a textbox.
This would obviously be a client side control, possibly a custom validator
with a function written in javascript.
Has anyone done this? Does someone have an example?

Regards



如果我没错,那就有一个maxlength (或类似的东西)财产

在文本框控件中。

Stefano Mostarda MCP

意大利罗马


Jerry写道:
If I''m not wrong, there is a maxlength (or something like that) property
in the textbox control.

Stefano Mostarda MCP
Rome Italy

Jerry wrote:
在将文本框输入限制为500个字符时,我想在用户输入文本框时包含一个
动态的字符输入数。这显然是一个客户端控件,可能是一个自定义验证器
带有用javascript编写的函数。
有没有人这样做过?有人有例子吗?

问候
In limiting textbox input to 500 characters I would like to include a
dynamic count of characters input while the user is typing into a textbox.
This would obviously be a client side control, possibly a custom validator
with a function written in javascript.
Has anyone done this? Does someone have an example?

Regards



这只会在用户点击外面时显示字符数

文本框 - 你可能想要的是保持一个正在运行的记录,而用户打字并且可能显示另一个表格字段

< script type =" text / javascript">

function countChar(str,f){

f.Count.value = str.length

}

< / script>

< form>

你输入了< input size = 3 type =" ;文本"名称= QUOT;计数"值= QUOT; 0">字符

< input type =" text"名称= QUOT; MYTEXT" onkeyup =" countChar(this.value,this.form)">

< / form>


Jon


" Kevin Spencer" <柯*** @ takempis.com>在消息中写道

news:uT ************** @ tk2msftngp13.phx.gbl ...
this would only show the character count when the user clicks outside the
textbox - what you probably want is to keep a running tally while the users
typing and maybe display it another form field
<script type="text/javascript">
function countChar(str,f){
f.Count.value = str.length
}
</script>
<form>
You''ve typed <input size=3 type="text" name="Count" value="0"> characters
<input type="text" name="MyText" onkeyup="countChar(this.value,this.form)">
</form>

Jon

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
在JavaScript中,你可以使用
值属性的length属性来获取字符数。将事件处理程序连接到
onchange文本框的属性,如下所示:

< script type =" text / javascript"><! -
function countChar(str)
{
window.status = str.length +"字符类型;
}
// - >< / script>
< input type =" text"名称= QUOT; MYTEXT" onchange =" countChar(this.value)">

-
HTH,
Kevin Spencer
.Net开发人员
Microsoft MVP <很多小东西组成了很多东西。

" Jerry" <济********* @ yahoo.com>在消息中写道
新闻:#g ************** @ TK2MSFTNGP12.phx.gbl ...
In JavaScript, you can use the length property of the value property of the textbox to get the number of characters. Wire your Event Handler to the
"onchange" property of the textbox, like so:

<script type="text/javascript"><!--
function countChar(str)
{
window.status= str.length + " characters typed";
}
// --></script>
<input type="text" name="MyText" onchange="countChar(this.value)">

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Jerry" <Je*********@yahoo.com> wrote in message
news:#g**************@TK2MSFTNGP12.phx.gbl...
在限制文本框输入为500个字符我想要在用户输入
文本框时包含一个
动态字符输入。这显然是一个客户端控件,可能是一个自定义的
验证器,其函数用javascript编写。
有没有人这样做过?有人有例子吗?

问候
In limiting textbox input to 500 characters I would like to include a
dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control, possibly a custom validator with a function written in javascript.
Has anyone done this? Does someone have an example?

Regards




这篇关于客户端字符数 - 文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆