2010-11-21 40 views
3

我已经通过这个网站搜索按钮,无法找到一个答案,我的问题..禁止使用jQuery

我有一个HTML表单,可以上传多张图片。看起来是这样的

<form enctype="multipart/form-data" method="post"> 
    <p> 
    <label for="image1">File number 1 to upload:</label> 
    <input id="image1" type="file" name="file[]" > 
    </p> 
     <p> 
    <label for="image1">File number 1 to upload:</label> 
    <input id="image1" type="file" name="file[]" > 
    </p> 
    //etc etc 
    </form> 

我想要做什么,是一个图像已被选定后,禁用每个“选择文件”按钮..

如果这是不可能有什么办法,我可以把显示器每次选择后都会显示'成功'信息? (可以有多达20个之多的上传按钮。)

感谢

回答

1

试试这个:

$(function(){ 
    $('#formID :file').change(function(){ 
    // if there is some value specified 
    if (this.value){ 
     $(this).attr('disabled', 'disabled'); 
    } 
    }); 
}); 

的代码应该禁用文件字段中指定的文件之后。 虽然我不认为这是好的做法,因为用户可能也想指定一个不同的文件。

1

使用change事件:

$('input[type="file"]').change(function() { 
    if($(this).val().length) 
     $(this).attr('disabled','disabled'); 

}); 
1

我想这是所有图像输入类型正确的监听器。

$(document).ready(function() { 
    //for all image inputs 
    $("input:file").change(function(){ 
    //check if an image is submitted 
    if(this.value){ 
     //disable element 
     $(this).attr("disabled", true); 
    } 
    }); 

}); 
+0

除了代码使用'file'类型而不是'image'。 – user113716 2010-11-21 17:10:37

+0

哎呀我的坏 - 修正 – liamfriel 2010-11-21 19:52:59

2

您有重复的ID "image1"。也许这只是在你的问题中,但如果它在你的代码中,请注意它是无效的。

这里的更快一点办法:

$('input:file').change(function() { 
    this.disabled = !!this.value; 
}); 
0

感谢大家的帮助,但没有工作!每次我使用脚本禁用按钮时,它都会取消上传。

我真的只需要一个视觉线索,点击一个按钮,所以我想出了这个,它在我的PHP页面中工作。

$(".classclick$count").click(function(){ 

    $(".classclick$count").append("<span style=color:red;> < DONE </span>"); 

});