为什么这个Java脚本不起作用 [英] why this java script not working

查看:84
本文介绍了为什么这个Java脚本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript">
var str = "abc";
var patt1 = /^[a-z]$/;
if(patt1.test(str))
{
document.write(str);
alert(str);
}
</script>



我想对字符串进行正则表达式匹配,然后发出警报



i want to make regular expression for string if it match then alert
what problem in this code?

推荐答案

/; 如果(patt1.test(str)) { 文档 .write(str); 警报(str); } </script>
/; if(patt1.test(str)) { document.write(str); alert(str); } </script>



我想对字符串进行正则表达式匹配,然后发出警报
这段代码有什么问题?



i want to make regular expression for string if it match then alert
what problem in this code?


问题与您使用的正则表达式有关.

试试:
Problem is with your regex expression used.

Try:
var str = "abc";
var patt1 = /[a-z]/i;

//Tests if the given string matches the Regexp, and returns true if matching, false if not.
if(patt1.test(str))
{
  document.write(str);
  alert(str);
}



在此处查看有关JavaScript Regex对象的详细信息: http://www.w3schools.com/jsref/jsref_obj_regexp.asp [ ^ ]



See details about JavaScript Regex object here: http://www.w3schools.com/jsref/jsref_obj_regexp.asp[^]


这工作正常,请检查并发布错误消息.
Hi this is working fine, please check and post error message.


这篇关于为什么这个Java脚本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆