当前位置: 编程技术>其它
关于IE的RegExp.exec的问题
来源: 互联网 发布时间:2014-10-16
本文导语: 代码如下: 代码如下: var st="A[B]C[D]E[F]G"; var reg =/[w]/ig; var s1 = st.replace(reg,""); var s2=[]; var arr; while((arr=reg.exec(st))!=null)s2.push(arr[0]); alert(s1); alert(s2.join("")); FF下正确显示,IE下S2为空. 网上查不到资料,请各位指点一二. 查询过程中得...
代码如下:
var st="A[B]C[D]E[F]G";
var reg =/[w]/ig;
var s1 = st.replace(reg,"");
var s2=[];
var arr;
while((arr=reg.exec(st))!=null)s2.push(arr[0]);
alert(s1);
alert(s2.join(""));
FF下正确显示,IE下S2为空.
网上查不到资料,请各位指点一二.
查询过程中得了个意外收获
var st="A[B]C[D]E[F]G";
var reg =/[w]/ig;
var s1 = st.replace(reg,"");
var s2=[];
var arr;
while((arr=/[w]/ig.exec(st))!=null)s2.push(arr[0]);
alert(s1);
alert(s2.join(""));
该写法IE死循环RegExp的lastIndex没有得到更新
In some recent code, I'm using Javascript to parse through the result set of an AJAX call, which happens to be returning a full HTML page. Yes, ideally, I'd have an AJAX call return something usable like JSON, but in this case the PHP back-end code had to remain as is and the front-end adjust to handle the legacy HTML it returned.
I needed to grab a link (1 or more) from the returned HTML page so that I could immediately display those links in separate windows (each was a generated report). So, my first stab at this is shown in the following code example. Basically, we have setup a string to represent the returned HTML, in this case it contains 3 links; and we want to use the standard Javascript RegExp object's exec() method to grab the URLS (href parameter) for each of those links. In our example, we just print them out in an unordered list to see what we've captured. The important lines of code we'll be looking at are highlighted in the example below.
代码如下:
var st="A[B]C[D]E[F]G";
var reg =/[w]/ig;
var s1 = st.replace(reg,"");
var s2=[];
var arr;
while((arr=reg.exec(st))!=null)s2.push(arr[0]);
alert(s1);
alert(s2.join(""));
FF下正确显示,IE下S2为空.
网上查不到资料,请各位指点一二.
查询过程中得了个意外收获
代码如下:
var st="A[B]C[D]E[F]G";
var reg =/[w]/ig;
var s1 = st.replace(reg,"");
var s2=[];
var arr;
while((arr=/[w]/ig.exec(st))!=null)s2.push(arr[0]);
alert(s1);
alert(s2.join(""));
该写法IE死循环RegExp的lastIndex没有得到更新
In some recent code, I'm using Javascript to parse through the result set of an AJAX call, which happens to be returning a full HTML page. Yes, ideally, I'd have an AJAX call return something usable like JSON, but in this case the PHP back-end code had to remain as is and the front-end adjust to handle the legacy HTML it returned.
I needed to grab a link (1 or more) from the returned HTML page so that I could immediately display those links in separate windows (each was a generated report). So, my first stab at this is shown in the following code example. Basically, we have setup a string to represent the returned HTML, in this case it contains 3 links; and we want to use the standard Javascript RegExp object's exec() method to grab the URLS (href parameter) for each of those links. In our example, we just print them out in an unordered list to see what we've captured. The important lines of code we'll be looking at are highlighted in the example below.
代码如下:
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!