http://www.baidu.com/s?
http://www.baidu.com/s?wd=1
http://www.baidu.com/s?wd=3第一个网站的时候返回空,并报错,怎么让他不报错?alert(/\??wd=([\d]*)/.exec(document.location.search)[1]);

解决方案 »

  1.   

    if判断一下是否为null啊 匹配上了再取
      

  2.   

    if((/\??wd=([\d]*)/.exec(document.location.search)[1])!=null)
    这样也报错呢?
      

  3.   

    额~~~
    if((/\??wd=([\d]*)/).exec(document.location.search)) !=null )){}
      

  4.   

    不为null的时候就取 【1】啊
    var reg = /\??wd=([\d]*)/;
    var str = document.location.search;
    var val = "";
    if(reg.exec(str) != null){
        val = reg.exec(str)[1];
    }
    也可以用match方法 这种正则不止exec这一种方法 呵呵