日期:2014-05-16 浏览次数:20413 次
$(document).ready(function(e) {
$('#upload').click(function(e){
$('body').append('<iframe name="cIfram" src="http://localhost/cross/cross.php" style="display:none;"></iframe>');
$('body').append('<form style="display:none;" id="form" action="http://localhost/cross/cross.php" method="post" target="cIfram" enctype="multipart/form-data" encoding="multipart/form-data"><input type="file" id="select" name="File"/></form>');
$('#select').change(function(e){
$("iframe[name='cIfram']").load(function(e) {
e.target.contentWindow.document.domain=document.domain='localhost';//这句是查资料说要使用同源策略,但是也没用啊,而且他们本身就是同源
console.log($($(this).contents().get(0)).find('body').html());
});
$('#form').submit();
});
$('#select').click();
return false;
});
});
$(document).ready(function(e) {
$('#upload').click(function(e){
var iframe = document.createElement("iframe");
iframe.setAttribute("id", "cIfram");
iframe.setAttribute("name", "cIfram");
iframe.setAttribute("src", "javascript:false;");
iframe.style.display = "none";
document.body.appendChild(iframe);
var form = document.createElement("form");
form.setAttribute("action", "http://localhost:8080/gtyz/test");
form.setAttribute("target", iframe.name);
form.setAttribute("id", "form");
form.setAttribute("name", "form");
form.setAttribute("enctype", "multipart/form-data");
form.setAttribute("method", "post");
form.style.display = "none";
document.body.appendChild(form);
var file = document.createElement("input");
file.setAttribute("id", "select");
file.setAttribute("type", "file");
form.appendChild(file);
$('#select').change(function(e){
$('#form').submit();
});
$('#select').click();
return false;
});
});