正则那些事
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,'') "/>
百闻不如一见,百见不如一做,只有做了,才知道问题出现在哪儿,才能去解决问题。

浙公网安备 33010602011771号