如何在选择文件时获取文件的完整路径 <input type=‘file’>
<input type="file" id="fileUpload">
<script type="text/javascript">
function getFilePath(){
$('input[type=file]').change(function () {
var filePath=$('#fileUpload').val();
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
但filePath var包含only name
所选文件,而不是full path
.
我在网上搜索过,但出于安全考虑,似乎浏览器(FF,chrome)只是给出文件名.
有没有其他方法来获取所选文件的完整路径?
我试图使用jQuery触发上传框(浏览按钮).
我现在尝试的方法是:
$('#fileinput').trigger('click');
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用.请帮忙.谢谢.
可能重复:
在上传图像之前预览图像
我有一个允许我的表格
<input type="file" name="filename" accept="image/gif, image/jpeg, image/png">
Run Code Online (Sandbox Code Playgroud)
浏览并选择一个文件.
我想要做的是在选择图像后立即显示该图像.这是在表单上的"提交"按钮被按下之前,因此图像几乎肯定存在于客户端.可以这样做吗?
在我的HTML表单中,我输入了类型文件,例如:
<input type="file" multiple>
Run Code Online (Sandbox Code Playgroud)
然后我通过单击该输入按钮选择多个文件.现在我想在提交表单之前显示所选图像的预览.如何在HTML 5中做到这一点?
我可能错过了一些简单的东西,但是当你读到的所有内容都不起作用时,它会非常烦人.我有可能在动态生成的页面过程中多次复制的图像.因此,显而易见的事情是预加载它并始终使用该变量作为源.
var searchPic;
function LoadImages() {
searchPic = new Image(100,100);
searchPic.src = "XXXX/YYYY/search.png";
// This is correct and the path is correct
}
Run Code Online (Sandbox Code Playgroud)
然后我使用设置图像
document["pic1"].src = searchPic;
Run Code Online (Sandbox Code Playgroud)
要么
$("#pic1").attr("src", searchPic);
Run Code Online (Sandbox Code Playgroud)
然而,像永远不会正确设置在Firebug当我查询图像,我得到[object HTMLImageElement]
的src
图像的
在IE中我得到:
http://localhost:8080/work/Sandbox/jpmetrix/[object]
Run Code Online (Sandbox Code Playgroud) 我正在尝试加载用户通过元素选择的图像.
我在输入元素中添加了一个onchange事件处理程序,如下所示:
<input type="file" name="picField" id="picField" size="24" onchange="preview_2(this);" alt=""/>
Run Code Online (Sandbox Code Playgroud)
而preview_2函数是:
var outImage ="imagenFondo";
function preview_2(what){
globalPic = new Image();
globalPic.onload = function() {
document.getElementById(outImage).src = globalPic.src;
}
globalPic.src=what.value;
}
Run Code Online (Sandbox Code Playgroud)
其中outImage具有我想要加载新图片的标签的id值.
但是,似乎onload永远不会发生,并且它不会向html加载任何内容.
我该怎么办?
我有一个上传控件用于将图像上传到服务器,但在上传之前我只想确保图像的尺寸是否正确.客户端是否可以使用javascript完成任何操作?
在我的代码中,我允许用户上传图像.现在我想在同一个弹出窗口中将此选定图像显示为预览.我怎么能用jQuery做到这一点?
以下是我在弹出窗口中使用的输入类型.
HTML代码:
<input type="file" name="uploadNewImage">
Run Code Online (Sandbox Code Playgroud) 我有一个 <input type="file" id="uploadPicture" value="123">
当我使用时: alert($("#uploadPicture").val());
它会提醒空对话框.
通常,我这样做:
$("document").ready(function() {
// The DOM is ready!
// The rest of the code goes here
});
Run Code Online (Sandbox Code Playgroud)
但文章建议使用:
// IIFE - Immediately Invoked Function Expression
(function($, window, document) {
// The $ is now locally scoped
// Listen for the jQuery ready event on the document
$(function() {
// The DOM is ready!
});
// The rest of the code goes here!
}(window.jQuery, window, document));
// The global jQuery object is passed as a parameter
Run Code Online (Sandbox Code Playgroud)
我可以看到那里的评论,但我无法弄清楚它到底在说什么. …
javascript ×7
jquery ×6
file-upload ×3
html ×2
html5 ×2
client-side ×1
css ×1
file ×1
filepath ×1
image ×1
input ×1
src ×1
upload ×1