[英]File input what am I doing wrong?
我一直在研究這個表單一段時間試圖獲取一個文本字段來模仿文件輸入字段(點擊它時觸發隱藏文件字段打開)。 我使用了一些Javascript來更改文本字段的VALUE,但我無法讓它工作。 在這里查看http://jsfiddle.net/ygMLm/ 。
<script type="text/javascript">
function getFile(){
document.getElementById("uploaded").click();
}
function sub(obj){
var file = obj.value;
var fileName = file.split("\\");
document.getElementById("upclicked").value = fileName[fileName.length-1];
document.adupload.submit();
event.preventDefault();
}
</script>
<p><input type="text" id="upclicked" onclick="getFile()" placeholder="Select a File (960 Width JPEG)"></p>
<div style='height: 0px;width: 0px; overflow:hidden;'>
<input type="file" name="date" value="" id="uploaded" onclick="getFile()">
編輯:
$('#uploaded').change(function(){
var file = obj.value;
var fileName = file.split("\\");
$('input[name=faux]').val(fileName[fileName.length-1]);
});
將此添加到您的jQuery代碼以在DOM就緒上運行:
$("#uploaded").change(
function() {
var fullPath = $(this).val();
var splitPath = fullPath.split("\\");
$("#upclicked").val(splitPath[splitPath.length - 1]);
}
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.