自动创建 form表单、动态创建 form表单


//  自动,动态创建 form表单 
function getUrl(URL, PARAMS) {
	var temp = document.createElement("form");
	temp.action = URL;
	temp.method = "post";
	temp.style.display = "none";
	if (PARAMS.length > 0) {
		for (var i = 0; i < PARAMS.length; i++) {
			var opt = document.createElement("textarea");
			opt.name = PARAMS[i].name;
			//防止IE浏览器将null 自动转换为"null" 导致错误
			if(PARAMS[i].value !== null){
				opt.value = PARAMS[i].value;
			}
			temp.appendChild(opt);
		}
	}
	document.body.appendChild(temp);
	temp.submit();
	return temp;
}

//调用方法
var PARAMS = [{"name":"id","value":id},{"name":"code","value":code}];
getUrl('这里写地址',PARAMS);


好啦就写到这里啦!

原文地址:https://www.cnblogs.com/yu-du-chen/p/12109031.html