自动创建 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);


好啦就写到这里啦!

posted @ 2018-12-04 15:45  羽渡尘  阅读(286)  评论(0编辑  收藏  举报