日期:2014-05-16 浏览次数:20501 次
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <input name="bbb" /> <script> list=document.getElementsByName("bbb"); if(list.length>0) { for(var i=0;i<list.length;i++) { list[i].onblur=function(){ var value=this.value; var pos=value.indexOf("/"); if(pos != -1) { this.value=value.slice(0,pos); } }; } } </script> </body> </html>
------解决方案--------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title>Untitled Document</title> <script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.min.js"></script> <script type="text/javascript"> $(function(){ var flagObj = 'zhaowei 12345/KF/huawei01'; $("input[type='text']").bind('blur',function(){ if($(this).val() == flagObj){ var tempValue = $(this).val().substring(0,$(this).val().indexOf("/",0)); $(this).val(tempValue); } }); }); </script> </head> <body> <div> AAA:<input type="text" name="name_a" value=""> <br> BBB:<input type="text" name="name_b" value=""> <br> CCC:<input type="text" name="name_c" value=""> <br> </div> </body> </html>