Javascript 未使用IE8触发Jquery事件
我正在使用blueimp的fileupload javascript小部件和jQuery 1.9.0将文件上载到服务器,我在IE8中没有触发一个事件,IE8是我的项目所需的浏览器之一 因此,由于这个原因,我无法打开窗口浏览文件。如果我从IE8控制台执行$('#fileupload')。click(),它会工作,但代码没有成功 我认为这是因为事件的泡沫,但我向你们展示了自己决定的代码。我还认为样式对这个问题很重要,因为我在真正的fileupload小部件上使用的样式按钮可能与它重叠。也许像不透明度和位置这样的css样式很重要 Html:Javascript 未使用IE8触发Jquery事件,javascript,jquery,internet-explorer,internet-explorer-8,blueimp,Javascript,Jquery,Internet Explorer,Internet Explorer 8,Blueimp,我正在使用blueimp的fileupload javascript小部件和jQuery 1.9.0将文件上载到服务器,我在IE8中没有触发一个事件,IE8是我的项目所需的浏览器之一 因此,由于这个原因,我无法打开窗口浏览文件。如果我从IE8控制台执行$('#fileupload')。click(),它会工作,但代码没有成功 我认为这是因为事件的泡沫,但我向你们展示了自己决定的代码。我还认为样式对这个问题很重要,因为我在真正的fileupload小部件上使用的样式按钮可能与它重叠。也许像不透明度
这已经开放足够长的时间了。看起来@Sampson是对的,IE8不支持文件的JSAPI。哪个版本的jQuery?只有1.x版本支持IE8。老IE和新IE之间的attachEvent/addEventListener差异可能存在问题。jQuery的版本是1.9.0@jonathansampson您能在JSFIDLE上安装一个复制程序让我们直接调试吗?您必须在更新版本的IE或其他浏览器中构建复制。@JonathanSampson单击“浏览”为我打开文件上载窗口。除此之外,如果你想获得IE8支持,你应该知道,
files
属性直到IE10才得到支持。
<form id="supportForm">
<div class="formTable">
<div class="formRow">
<label>User:</label>
<input name="user" type="text" class="form-control validate[required]" placeholder="John Smith">
</div>
<div class="formRow">
<label>Phone:</label>
<input name="phone" type="tel" class="form-control validate[required]" placeholder="Ej: 881243989">
</div>
<!-- ... -->
<!-- Some inputs and stuff -->
<!-- ... -->
<div class="formRow">
<label>Attached files:</label>
<div class="formCell">
<span class="btn btn-default fileinput-button">
<span>Browse</span>
<input id="fileupload" type="file" name="files[]" data-url="../server/upload.html" class="submitFilesButton" multiple="">
</span>
</div>
</div>
<div class="formRow">
<label></label>
<div id="additional" class="formCell">
</div>
</div>
<div class="formRow">
<label></label>
<div class="formCell">
<button id="remedyButton" type="submit" class="btn btn-primary">Send</button>
<button id="resetButton" type="reset" class="btn btn-default">Clean</button>
</div>
</div>
</div>
</form>
$(document).ready(function() {
upload_comp = $('#fileupload')
.fileupload({ // Widget options
singleFileUploads : false,
autoUpload : false,
dataType : 'json'
})
.on("fileuploadadd",
function(e, data) { // Function for adding files after opening the browse window
if (data.files.length > 0) {
$('input[type=file]').css('color', 'transparent');
}
// Creating divs for the selected files in the previous browse window
for ( var i = 0; i < data.files.length; i++) {
var name = $('<div></div>').text(data.files[i].name);
var icon = $('<span class="fa fa-2x fa-trash" data-toggle="tooltip" data-placement="bottom" title="Delete">');
icon.click(function() {
// This handler creates a button for removing the actual file
for ( var k = 0; k < fileList.length; k++) {
if (fileList[k].name == $(this).parent().text()) {
fileList.splice(k, 1);
break;
}
}
$(this).parent().remove();
});
fileDiv = $('<div class="item">').wrapInner(name).append(icon);
fileDiv.appendTo($('#additional'));
fileList.push(data.files[i]);
}
//createTooltip($('.fa-trash'));
});
if (isNavigator(CONSTANTS.BROWSER.IE8)) {
// Maybe could use something here and force the click()
// But my current solution creates an infinite loop
}
});
/* These are specifically for IE8 and are located in ie8.css */
DIV.formRow > * {
width: auto;
}
INPUT[type=file] {
display : none;
}
/* These are for all browsers in another css file, also for IE8 when there is no rule in the previous file */
.formTable {
border-spacing:1em;
display: table;
width: 45em;
min-width:45em;
margin: 0 auto;
}
div.formRow {
display: table-row;
}
div.formRow > label, #additional {
width: 35%;
}
div.formRow > * {
display: table-cell;
width: 100%;
}
div.formCell {
display: table-cell;
width: 100%;
}
#fileupload {
float:left;
top: 0;
right: 0;
left: 0;
margin: 0;
position: absolute;
width: 100%;
height: 100%;
padding: initial;
}
.item {
border: 1px;
border-color: black;
border-style: solid;
border-radius: 5px;
border-width: thin;
display: inline-block;
padding: 4px;
margin:0.25em;
}
.item div {
vertical-align:text-bottom;
display: inline;
}
.fa-trash {
margin-left: 1em;
cursor:pointer;
color: #428BCA;
}
#company {
display: inline-block;
width: 49%;
}
#warehouse {
float:right;
width: 49%;
display: inline-block;
}
.submitFilesButton {
opacity:0;
position:absolute;
}
.fileinput-button {
text-align:center;
white-space: nowrap;
position: relative;
}
#resetButton, #remedyButton {
margin: 0.4em;
float:right;
}
label {
vertical-align:top;
}