1
我想寫一個程序,使用簡單的html輸入type="text"
和一個按鈕,它將執行輸入type="file"
的功能。我可以使用<input type =「text」>來模擬<input type =「file」>嗎?
我想寫一個程序,使用簡單的html輸入type="text"
和一個按鈕,它將執行輸入type="file"
的功能。我可以使用<input type =「text」>來模擬<input type =「file」>嗎?
理論上你可以破解它(設置0不透明度來輸入[文件]等),但手動鍵入文本字段的路徑將無法正常工作(不會發送帶有窗體的文件)。 這似乎是很多不必要的黑客行爲。是什麼原因?
HTML來源:
<input type="file" class="file">
<input type="text" name="file" class="sfile">
<input type="submit" value="send file" name="submit">
CSS:
.file{
visibility:hidden; # don't use display:none; because IE compability in js
}
的jQuery:
$('.sfile').click(function(){
$('.file').click();
});
$('.file').change(function(){
$('.sfile').val($(this).val());
});
可以使文件輸入隱藏,使按鈕觸發文件的onclick。它的工作,但它是一個很大的努力 –
我的猜測是,你想要一個樣式的文件輸入。如果是這樣的話,請看這裏:http://stackoverflow.com/questions/3226167/how-to-style-input-file-with-css3-javascript –