2012-04-19 11 views
0

javascriptで入力ファイルタイプを作成しました。入力ファイルタイプのブラウズボタンが表示されない

私は期待どおりに入力タイプのファイルが生成されますが、参照ボタンが表示されません。

は、私は、入力ファイルの種類のCSSスタイルを検索するが、私が見るすべては

ブラウザボタンをカスタマイズする方法でした。以下は私の画面の様子です。

enter image description here

通常、ファイルの種類は、第1として登場しなければならないが、私

は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

+0

私のコード –

答えて

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

が更新されました。あなたはalvin! –

0

Safari、Firefox、Chromeで正しく表示できます。 http://jsfiddle.net/MWtzh/

使用しようとしているブラウザはありますか? IE8の古いバージョンを含む一部の古いIEバージョンでは、HTML5がサポートされていません。 はこちらをご覧:私はaddmorefiles(という名前の関数の中で何が変わったDoes Internet Explorer 8 support HTML 5?

+0

私はtomcatとeclipse EEを使用しています。このコードはブラウザでは実行されていないため、ブラウザ関連の問題ではない可能性があります。コメントをいただきありがとうございます。 –

+0

あなたの質問は「ブラウズボタンが表示されませんでした」でしたか?私はあなたの質問を理解していないと思います。とにかくあなたの質問が解決される、楽しむ:) – Ankit

+0

ああええ...私の賭け。第二言語で何かを説明することは常に困難です。私は英語が私の主要な言語だと思っていますが、まあまあ..私ができる限り説明しようとすると思います。 –

0

ルック氏SEHOリー

)は以下の通りです:

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); 

私はuが属性「タイプを設定するのを忘れたと思いますfileform 『

「与えられた参照ボタンは、』

あなたはまたで試すことができます...私はそれを実装している、それが動作します私の答えとあなたの機能を置き換える.... uがuは

関連する問題