2012-04-19 85 views
0

我通過javascript製作了一個輸入文件類型。我看不到輸入文件類型中的瀏覽按鈕

輸入類型文件生成如我所料,除了我看不到瀏覽按鈕。

我搜索輸入文件類型的CSS樣式,但我看到的是如何定製

瀏覽器按鈕。以下是我的屏幕外觀。

enter image description here

通常,文件類型應該表現爲第二個,但我得到第一個,當我

產生的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> 

有人可以告訴我我做錯了什麼嗎?提前致謝。

+0

你能告訴我們完整的代碼嗎? – 11684 2012-04-19 06:41:42

+0

我現在更新了我的代碼 – 2012-04-19 06:47:04

回答

1
var fileForm = document.createElement('input'); 
fileForm.type = 'file'; // only <input type="file"> has browse button 
+0

! thx alvin! – 2012-04-19 06:52:50

0

我可以在Safari,Firefox和Chrome上正確查看它。 http://jsfiddle.net/MWtzh/

是否有任何特定的瀏覽器正在嘗試使用它? 包括IE8舊版本的一些較舊的IE版本不支持HTML5。 看一看這裏:Does Internet Explorer 8 support HTML 5?

+0

我正在使用tomcat和eclipse EE。此代碼沒有在瀏覽器上運行,所以這可能不是瀏覽器相關的問題。感謝您的評論。 – 2012-04-19 07:00:48

+0

你的問題是「瀏覽按鈕沒有出現」?我想我還沒有理解你的問題。無論如何,您的查詢解決了,請享受:) – Ankit 2012-04-19 07:04:30

+0

哦耶...我的賭注。用第二語言解釋某些東西總是很難。我希望英語是我的主要語言,但..哦,好吧..猜我應該嘗試解釋,盡我所能。 – 2012-04-19 07:15:01

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’

我已經實現了它和它的作品...

您還可以通過嘗試取代你的功能與我的答案....你會得到你想要的

試試吧....

相關問題