您的位置:首页 > Web前端 > JavaScript

<a>标签模拟post提交方式

2013-11-12 10:27 197 查看

<a>标签模拟post提交方式

本人在项目中遇到要使用<a>标签发送post请求,现将解决方案整理如下:

方法一:

    1、编写javascript函数,模拟post提交:

function post(URL, PARAMS) {
var temp = document.createElement("form");
temp.action = URL;
temp.method = "post";
temp.style.display = "none";
for (var x in PARAMS) {
var opt = document.createElement("textarea");
opt.name = x;
opt.value = PARAMS[x];
temp.appendChild(opt);
}
document.body.appendChild(temp);
temp.submit();
return temp;
}
    2、在<a>标签中调用:
        方式1:

                 

<span style="font-family:KaiTi_GB2312; font-size:14px"><a href="javascript:post('${ctx}/system/user!toMain.action',{areaId:'${section.id}',chkId:'${role.id}'});" >• ${section.showName}-${role.roleName }</a></span>


        方式2:
<span style="font-family:KaiTi_GB2312; font-size:14px"><a href="javascript:void(0);" onclick="post('${ctx}/system/user!toMain.action',{areaId:'${section.id}',chkId:'${role.id}'})" >• ${section.showName}-${role.roleName }</a></span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  html javascript a