选择文件时的操作
action when file selected
当用户在。我不确定我的代码是否真的进入了我的javascript,这是我的代码:
function showNoFile() {
if(document.getElementById("video-file-upload").value != "") {
alert("yeap");
}
}
/*****************
UPLOAD BUTTON
******************/
.file-wrapper {
cursor: pointer;
display: inline-block;
overflow: hidden;
position: relative;
margin:10px;
}
.file-wrapper input {
cursor: pointer;
font-size: 100px;
height: 100%;
-moz-opacity: 0.01;
opacity: 0.01;
position: absolute;
right: 0;
top: 0;
}
.file-wrapper .button {
background: #F3A662;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 11px;
font-weight: bold;
margin-right: 5px;
text-transform: uppercase;
}
<form id="video_uploader" name="video_uploader" action="uploader.php" method="post" enctype="multipart/form-data">
<span class="file-wrapper btn ad-choice">
<input type="file" name="file" id="video-file-upload" />
<span class="button">Choose a video</span>
</span>
<br/>
<input type="submit" name="submit" value="Submit" />
</form>
在DOM就绪上使用它
$("#video-file-upload").change(function(){
if($(this).val() != ""){
alert("some file selected");
}
});
Fiddle
if (document.getElementById("video-file-upload").files.length == 0) {
alert("yeap");
}
检查文件。长度等于0。
带有javascript:
function showNoFile() {
if(this.value != "") {
alert("yeap");
}
}
document.getElementById("video-file-upload").onchange = showNoFile;
function showNoFile() {
if(this.value != "") {
alert("yeap");
}
}
document.getElementById("video-file-upload").onchange = showNoFile;
/*****************
UPLOAD BUTTON
******************/
.file-wrapper {
cursor: pointer;
display: inline-block;
overflow: hidden;
position: relative;
margin:10px;
}
.file-wrapper input {
cursor: pointer;
font-size: 100px;
height: 100%;
-moz-opacity: 0.01;
opacity: 0.01;
position: absolute;
right: 0;
top: 0;
}
.file-wrapper .button {
background: #F3A662;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 11px;
font-weight: bold;
margin-right: 5px;
text-transform: uppercase;
}
<form id="video_uploader" name="video_uploader" action="uploader.php" method="post" enctype="multipart/form-data">
<span class="file-wrapper btn ad-choice">
<input type="file" name="file" id="video-file-upload" />
<span class="button">Choose a video</span>
</span>
<br/>
<input type="submit" name="submit" value="Submit" />
</form>
相关文章:
- 无法执行文件.退出Acrobat PDF中的操作
- Redux:为什么不把操作和reducer放在同一个文件中呢
- javascript下载一个文件并执行提交操作
- 我如何从javascript文件中AJAX发布到MVC操作
- 我无法在操作方法中将我的文件传递给 httppostedfilebase
- 当我在操作属性中写入页面名称时,文件图像不会上传
- 在rails中操作上传的svg文件
- 带有所有用户操作的业务逻辑的Javascript配置文件
- 如何将HTML页面操作的范围限定为JS/Coffee文件中的唯一UserId
- 选择文件时的操作
- 如何将JavaScript文件路径映射到ASP.Net MVC控制器操作
- 只有最后一个文件是通过迭代形式.submit()操作下载的
- 将JSON从索引操作服务到公用文件夹中的index.html
- nodejs:原子文件替换操作,只触发一次一些观察者
- 将java脚本变量传递给相同的表单操作php文件参数
- 使用 1 个浏览操作更新 2 个输入文件类型字段
- 在浏览器上传后操作文件对象的正文
- 找不到将隐藏值传递给操作文件的方法
- 通过雷鸟扩展操作文件系统
- 使用Javascript或jQuery操作文件