<input class="resourcesName" onkeyup='this.value=this.value.replace(/[:|:|*|?|?|"|“|\\|/|\|]/g, "")' type="text" />
css样式 :
.test_box { width: 400px; min-height: 120px; max-height: 300px; _height: 120px; margin-left: auto; margin-right: auto; padding: 3px; outline: 0; border: 1px solid #a0b3d6; font-size: 12px; word-wrap: break-word; overflow-x: hidden; overflow-y: auto; }
html :
1 <div class="test_box" contenteditable="true"></div>
脚本:
//标签检测 $(".test_box").bind("blur", function(){ var labels = $(this).html(); var array = labels.split(","); var length= array.length; for(var i=0; i < length; i++){ var str = array[i].split(","); var len = str.length; for(var j=0; j < len; j++){ var reg = /^[a-zA-Z\d\u4E00-\u9FA5]{1,10}$/; if(!reg.test(str[j])){ alert("出错!"); //return false; } } } });
文本框用红色底色闪烁几秒进行提示:
/**
* 提示的样式编辑
*/
.red{ border:1px solid #d00; background:#ffe9e8; color:#d00;}
//引用方法
shake($("#inputName"),"red",5);
/**
* 闪烁方法
*/
function shake(ele,cls,times){ var i = 0; var t= false; var o =ele.attr("class")+" "; var c =""; var times=times||2; if(t) return; t= setInterval(function(){ i++; c = i%2 ? o+cls : o; ele.attr("class",c); if(i==2*times){ clearInterval(t); ele.removeClass(cls); } },200); };
在线编辑器学习地址:http://kindeditor.net/