0

我通过javascript创建了一个输入文件类型。

输入类型文件按我的预期生成,除了我看不到浏览按钮。

我搜索了输入文件类型 css 样式,但我看到的只是如何自定义

浏览器按钮。下面是我的屏幕的样子。

在此处输入图像描述

通常,文件类型应该显示为第二个,但是当我得到第一个时

在 javascript 中生成文件类型。下面是我的代码。

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
.uploadForm{
type:file; position:relative;
}

#addBtn{
width:100px; height:20px;
}
</style>
<script>
function addMoreFiles(){
var fileForm = document.createElement('input');
var addButton = document.createElement('button');   
addButton.setAttribute('onclick', "addMoreFiles()");
addButton.setAttribute('id', "addBtn");
fileForm.className = 'uploadForm';
document.getElementById('uploadDiv').appendChild(fileForm);
document.getElementById('uploadDiv').appendChild(addButton);
}
</script>
</head>
<body onload="addMoreFiles()">
<form name="frmname" method="post" enctype="multipart/form-data" action="./ViewPage.jsp">
file<br>
<div id="uploadDiv"></div>
<br>
<input type="file" name="uploadFile"><br>
<input type="submit" value="upload"><br>
</form>
</body>
</html>

谁能告诉我我做错了什么?提前致谢。

4

3 回答 3

1
var fileForm = document.createElement('input');
fileForm.type = 'file'; // only <input type="file"> has browse button
于 2012-04-19T06:49:27.820 回答
0

看 Seho Lee 先生

我在名为 addmorefiles() 的函数中所做的更改如下:

function addMoreFiles(){
var fileForm = document.createElement('input');
var addButton = document.createElement('button');   
fileForm.setAttribute('type', "file"); //by this we are setting type of button...which u missed to put
addButton.setAttribute('onclick', "addMoreFiles()");
addButton.setAttribute('id', "addBtn");
fileForm.className = 'uploadForm';
document.getElementById('uploadDiv').appendChild(fileForm);
document.getElementById('uploadDiv').appendChild(addButton);

我想你忘了为给定的浏览按钮“fileform”设置属性“type”

我已经实现了它并且它有效......

您也可以尝试用我的答案替换您的功能......你会得到你想要的

试试看....

于 2012-04-19T07:07:56.557 回答
0

我能够在 Safari、Firefox 和 Chrome 上正确查看它。 http://jsfiddle.net/MWtzh/

您是否正在尝试使用任何特定的浏览器?一些较旧的 IE 版本包括 IE8 旧版本不支持 HTML5。看看这里:Internet Explorer 8 是否支持 HTML 5?

于 2012-04-19T06:57:44.313 回答