========= input ============================================
//一般用于文件上传,但又不想用原生file界面(美化标签后的触发函数)
var fileTips = document.createElement("input");
fileTips.setAttribute("type","file");
fileTips.setAttribute("onchange","getfile(this)");
fileTips.click();
function getfile(obj){
var formData = new FormData();
formData.append('file', obj.files[0]);
$.ajax({
url: '',
type: 'POST',
data: formData,
dataType: 'JSON',
cache: false,
processData: false,
contentType: false,
success: function (data) {
//do
},
error: function (data) {
//do
}
});
}
========= a ================================================
var aTips = document.createElement("a");
aTips.setAttribute("href","https://www.baidu.com");
aTips.setAttribute("target","_blank");
========= form =============================================
var params = new Array();
params.push({"name":"admin","value":"123"});
postcall("/xxx", params);
function postcall(url,params){
var tempForm = document.createElement("form");
tempForm.action = url;
tempForm.method = "post";
tempForm.target = "_blank";
tempForm.style.display = "none";
params.forEach(function(item,index){
var opt = document.createElement("input");
opt.name = item.name;
opt.value = item.value;
tempForm.appendChild(opt);
});
document.body.appendChild(tempForm);
tempForm.submit();
document.body.removeChild(tempForm);
}