87,955
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
function getCookie(name)//取cookies函数
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]);
return null;
}
<html>
<body>
<script type="text/javascript">
var str="1 plus 2 equal 3";
var arr=str.match(/\d+/);
document.writeln(arr[0]);
document.writeln(arr[1]);
document.writeln(arr[2]);
</script>
</body>
</html>
结果居然是:1 undefined undefined
为什么这里的arr[2]又取不到了?