猿问

iframe传参问题

在一个页面index.html中,使用到了iframe


 <iframe name="iFrame" allowtransparency="true" src="/aaa/bbb.html?name="tom"&sex="male" width="100%" height="100%" 

  id="student" style="border: none;">


这个iframe引入了另一个页面bbb.html,并且传入了两个参数name和sex但是在bbb.html页面中如何获得这两个参数呢?我在页面中一直是undefined?


喵喵时光机
浏览 314回答 1
1回答

烙印99

方法如下://获取URL中参数function getUrlParam(name) {&nbsp; &nbsp; var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象&nbsp; &nbsp; var r = window.location.search.substr(1).match(reg); //匹配目标参数&nbsp; &nbsp; if (r != null) return unescape(r[2]);//返回参数值&nbsp; &nbsp; return null;&nbsp;}以你的页面为例:在bbb.html页面中,调用getUrlParam('name')和getUrlParam('sex')即可
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答