如何在文本框中输入数字 [英] how to write number in text box
本文介绍了如何在文本框中输入数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想记录一下单击按钮的次数,但文本框上没有任何显示.
谁能告诉我如何在文本框中显示计数吗?
提前谢谢.
Hi all,
I want to write count of how many times i clicked the button but nothing is shown on textbox.
Can anyone tell me how to show the count in textbox?
Thanks in advance.
<html>
<head>
<script type="text/javascript">
function init()
{ct=0;
function count()
{ct++
document.forms["f1"].elements["count"].Value=ct;}
}
</script>
</head>
<body>
<form name="f1">
<input type = "button" name="button2" value="Check Count" = "count()">
<input type = "text" name="count" size="5">
</form>
</body>
</html>
推荐答案
<html>
<head>
<script type="text/javascript">
function init()
{ct=0;
function count()
{ct++
document.forms["f1"].elements["count"].Value=ct;}
}
</script>
</head>
<body>
<form name="f1">
<input type = "button" name="button2" value="Check Count" = "count()">
<input type = "text" name="count" size="5">
</form>
</body>
</html>
您真的希望这行得通吗?与
init
中缺少}
ct++
缺少;
还有诸如"Check Count" = "count()"
之类的未知物
试试这个
You really expect this to work? with
missing }
in init
missing ;
for ct++
and something unknown like "Check Count" = "count()"
Try this
<html>
<head>
<script language="JavaScript">
var count=0;
function myFun(f) {
count += 1;
f.myText.value = count;
}
</script>
</head>
<body>
<form>
<input type="text" name="myText" value=""><br>
<input type="button" name="myBut" value="Click" onClick="myFun(form)">
</form>
</body>
</html>
这篇关于如何在文本框中输入数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文