如题
比如: aaa<Input type=text name="bbb" value="" />
我需要给aaa中如果输入zhaowei 12345/KF/huawei01,都被截取成zhaowei 12345
js或者jquery

解决方案 »

  1.   

    补充一下:我不是只给一个页面加上这个控制事件,是给所有的jsp页面都加上这个事件
      

  2.   

    没看懂 aaa是个什么东西?
      

  3.   

    <Input type=text name="bbb" value="" />
    我需要给aaa中如果输入zhaowei 12345/KF/huawei01,都被截取成zhaowei 12345意思就是遍历所有的jsp页面,如果有aaa<Input type=text name="bbb" value="" />,就要加上一个控制事件,我需要给bbb中如果输入zhaowei 12345/KF/huawei01,都被截取成zhaowei 12345

    急要,谢谢,我分给少了,如果帮我搞定,我会加分
      

  4.   

    “遍历”所有的jsp页面是不现实的。
    你可以在每个页面中都引入一个js文件。
    <script src="a.js"></scirpt>
    然后在js代码如下,脱离焦点以后截取。<!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>
      

  5.   


    <!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>