以这种方式看看,form和iframe都是动态构造
[code="java"]
function submitForm(url)
{
var id =new Date().getTime();
var createForm=function(){
var oForm=document.createElement('FORM');
oForm.id='form_'+id;
oForm.action=url;
oForm.method='POST';
if(oForm.encoding){
oForm.encoding = 'multipart/form-data';
}
else{
oForm.enctype = 'multipart/form-data';
}
//创建form里的文本框
document.body.appendChild(oForm);
};
var createIFrame=function(){
var oIFrame={};
try{
oIFrame = document.createElement("<IFRAME name=frame_"+id+" />");
}catch(e){
oIFrame=document.createElement("IFRAME");
oIFrame.name='frame_'+ id;
}
oIFrame.name ='frame_'+ id;
oIFrame.width=0;
oIFrame.height=0;
oIFrame.frameBorder=0;
oIFrame.id='frame_'+id;
document.body.appendChild(oIFrame);
return oIFrame;
};
createForm();
var oFrame=createIFrame();
var oForm=document.getElementById('form_'+id);
var uploadCallback=function(){
var thisDocument=oFrame.contentDocument||oFrame.contentWindow.document;
var html=thisDocument.body.innerHTML;
setTimeout(function(){try{
oForm.parentNode.removeChild(oForm);
oFrame.parentNode.removeChild(oFrame);
} catch(e){
throw e;
}
}, 100);
};
if(window.attachEvent){
oFrame.attachEvent('onload', uploadCallback);
}
else{
oFrame.addEventListener('load', uploadCallback, false);
}
oForm.setAttribute("target",oFrame.name);
oForm.submit();
}
[/code]