有时候我们需要用到 iframe ,同时需要向 iframe 传递参数,那么我们需要如何去实现这一功能呢?
我们可以使用 JavaScript 来实现。
前端代码
JavaScript 代码
在同一页面写以下的 JavaScript 函数:
function local_action(vaule)
{
//这里的作用是在不刷新页面的前提下,重置action地址
document.pxform.action="nowamagic.php";
if(1 == vaule)
{
//在响应页面加上GET参数后缀
document.pxform.action+="?status=1";
}
if(5 == vaule)
{
document.pxform.action+="?status=5";
}
if(9 == vaule)
{
document.pxform.action+="?status=9";
}
//提交
document.pxform.submit();
}
根据传递给函数的参数来写入 nowamagic.php 页面的后缀GET参数。