正则那些事

1.利用正则提取URL后面的请求页数

<html>
<head>
<title></title>
<script type="text/javascript">
window.onload=function(){
var urlStr='https://www.baidu.com/s?pIndex='+45;
var rec=/=(.+)/.exec(urlStr)[1];
alert(rec);
}
</script>
</head>
<body>

</body>
</html>

运行后弹出的是45。

 有关更多正则学习,请详见:http://www.cnblogs.com/jamesping/articles/2252675.html#undefined

2.利用正则限制输入框只能输入数字

<input type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'') "/>

  

posted @ 2016-07-05 18:05  shuai7boy  阅读(153)  评论(0编辑  收藏  举报