判断JSON返回的对象中的firstName这一列的值是否包含指定的字符,如果包含指定字符则返回true,否则返回false 1. [代码] [其他]代码 !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"htmlheadtit
1. [代码][其他]代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>a.html</title> <script type="text/javascript"> function al(){ var txt=document.getElementById("aa").value; var reg=/^\d{1,20}:[A-Za-z0-9\s\u0800-\u9FA5\@\#\!\-\+\$\^\&\*\_\=]{1,30}$/; if(reg.test(txt)){ alert("匹配"); }else { alert("不匹配"); } var flag=test(); alert(flag); } function test(){ var tt=false; var employees = [ { "firstName":"Bill" , "lastName":"Gates" }, { "firstName":"George" , "lastName":"Bush" }, { "firstName":"Thomas" , "lastName": "Carter" } ]; var name="George"; for(var i=0;i<employees.length;i++){ if(name==employees[i].firstName){ tt= true; return tt; } } tt= false; return tt; } </script> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <form> <input id="aa" value="123: に111111111111111111っぽん收拾收拾啊啊1" onclick="al()" /> </form> </body> </html>