关于限制 textarea 文本域输入行数的实现。
相比大家都网速购过物,快递单号也是大家关注自己货物动态的唯一凭证。
在我们查询快递单号的时候,可以进行多个单号的查找。下面我自己模仿快递单号的多个查询一个例子。
[caption id="" align="alignnone" width="268"]
关于限制 textarea 文本域输入行数的实现[/caption]
关于限制 textarea 文本域输入行数的实现[/caption]下面是Html 页面的演示代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function checkLength(){
var searchText = $("#searchText").val();
var searchArray = searchText.split("\n");
if(searchArray.length > 10){
return false;
}
}
</script>
</head>
<body>
<div align="center" style="width:250px;">
<div class="goods_list">
<div class="" style="text-align: left;padding-left: 30px;padding-top:10px;padding-bottom:10px;">
<h3>SN查询</h3>
</div>
<table cellpadding=0 cellspacing=0>
<tr>
<td style="width: 90px;text-align:right;" valign="top" ><span>输入:</span></td>
<td class="main_content_right" valign="top" style="width:150px;"><table>
<tr>
<td style="height:25px;"><select style="width:100%;" name="searchType">
<option value="3">单据SN</option>
</select></td>
</tr>
<tr>
<td><textarea rows="10" name="searchText" id="searchText" onkeypress="return checkLength();" ></textarea></td>
</tr>
<tr>
<td ><div class="operate" style="margin: 5px 0px;padding-left:8px;"> <span>
<input type="button" value="查询" onclick="search();" class="refer_button" style="margin: 0px;"/>
<input class="refer_button" value="重置" type="reset" style="margin: 0px;"/>
</span> </div></td>
</tr>
</table></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
个人比较懒,代码优化什么的对我来说都是浮云,基本懒的折腾。(提示:所以,如果感觉此段代码能帮到你的,在使用前先做写优化。)
评论