原生js实现form表单提交

最近工作比较忙,着急上线,写个简单的东西吧
url为你要提交的地址 params 为你提交的参数

function fromPost(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];
                        // alert(opt.name)
                        temp.appendChild(opt);
                    }
                    document.body.appendChild(temp);
                    temp.submit();
                    return temp;
                }

猜你喜欢

转载自blog.csdn.net/lbchenxy/article/details/97932056
今日推荐