html中的表单怎么控制其长度??

html中的表单怎么控制其长度??,第1张

1. 长度限制

<script>

function test()

{

if(document.a.b.value.length>50)

{

alert("不能超过50个字符!")

document.a.b.focus()

return false

}

}

</script>

<form name=a onsubmit="return test()">

<textarea name="b" cols="40" wrap="VIRTUAL" rows="6"></textarea>

<input type="submit" name="Submit" value="check">

</form>

~~~~~~~~~~~

表单项输入数值/长度限定

<script language="javascript">

<!--

function CheckForm()

{

if (document.form.count.value > 100 || document.form.count.value < 1)

{

alert("输入数值不能小于零大于100!")

document.form.count.focus()

return false

}

if (document.form.MESSAGE.value.length<10)

{

alert("输入文字小于10!")

document.form.MESSAGE.focus()

return false

}

return true

}

//-->

</script

html表单中输入字符的最小长度是1个字符。

用input text标签的maxlength属性即可实现,代码如下:

<input type="text" maxlength="XX" />

maxlength 属性后面设置需要限制的字段长度即可。

js:

function btnck(){

var a=document.getElementById("text")

var b=document.getElementById("btn")

if(a.value==""){

alert("文本框内容不能为空!")}

else{

alert("提交成功!")}

}

html:

<input id="text" type="text" />

<input id="btn" type="button" onclick="btnck()" value="提交" />


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7068854.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-01
下一篇 2023-04-01

发表评论

登录后才能评论

评论列表(0条)

保存