Javascript 设置textarea输入框的最大值
<html>
<head>
<title>测试输入字符</title>
<script language=javascript>
String.prototype.lenB =function(){
return this.replace(/[^\x00-\xff]/g,"**").length;
}
function a(){
var str=document.getElementById("content").value;
if(str.length <= 180){
abc.innerText="您已经输入"+str.length+"/180个字(每条短信最多70个字,超过分多条发送)";
}else{
abc.innerText="最多只允许输入180个字。"
}
}
</script>
</head>
<body>
<textarea onpropertychange="if(value.length>80) value=value.substr(0,80)" id="content" onkeyup="a();"></textarea>
<input maxlength="5"/>
<p id="abc"></p>
</body>
</h tml>
相关文档:
方法: string.replace(new RegExp(oldString,"gm"),newString))
gm g=global, m=multiLine,大致上方法就是这样的,可以实现替换全部指定字串
另一个简单的验证JS的方法:
在浏览器地址栏输入
javascript:alert("abcabcabc".replace(new RegExp("a","gm"),"ad&quo ......
<mce:script type="text/javascript"><!--
function SetCookie(name,value,expire) {
var exp = new Date();
exp.setTime(exp.getTime() + expire);
document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
} ......
Link:http://topic.csdn.net/u/20100317/15/687e21bc-40f3-4f0e-bc22-5f2a32ceb1a3.html?seed=1664090183&r=63989333#r_63989333
<HTML>
<head>
<title>sample</title>
<mce:script language="JavaScript"><!--
var c="FFFFFF";
window.onload=function (){
setInterval(s ......