我正在将输入动态添加到我的页面中,因此需要使用.on将事件附加到它们.
我正在尝试将更改事件附加到type =“file”输入,但它只是不起作用.
我试过两种方法,第一种:
$('.container').on('change','.file-input-hidden',function(){
第二个:
$('.container').on('change','input[type="file"]',function(){
出了什么问题?
编辑:
和js:
$('.container').on('click','.file-browse',function(){
var thisone = $(this).attr('id');
$('input[name="input-'+ thisone+'"]').click();
});
$('.file-input-hidden').on('change',function(){
var thetext = $(this).val();
var thetextsplit = thetext.split('\\').pop();
var thisone = $(this).attr('name').split('-').pop();
if($('.file-info').text() == thetextsplit){
alert('you have already selected this file');
$(this).replaceWith( $(this).val('').clone( true ) );
}
else{
$('#info-'+ thisone).text(thetextsplit);
$('#clear-'+ thisone).fadeIn(100);
var emptyinputs = $('.file-info:empty').length;
if(emptyinputs <1){
var filledinputs = $(".file-info:contains('.')").length;
var thisnumber = filledinputs + 1;
var filecontainer = $('browse = $('browse').attr('id','file'+thisnumber).text('browse');
var fileclear = $('browse,fileclear);
filecontainer.appendTo(thebody);
var theform = $('#hidden-inputs');
newinput.appendTo(theform);
}
}
if($(this).val() == ''){
$('#clear-'+thisone).fadeOut(100);
}
});
$('.container').on('click','.file-clear',function(){
var thisone = $(this).attr('id').split('-').pop();
$('input[name="input'+ thisone +'"]').replaceWith( $('input[name="input'+ thisone +'"]').val('').clone( true ) );
$('#info-'+ thisone).text('');
$(this).fadeOut(100);
});
HTML:
browse" id="file1">browse
最佳答案
你的代码……
jQuery的:
$('.container').on('change',function(){
HTML:
它不起作用,因为输入[type =“file”]不在.container中.
把它放在div.container里面或试试这样的东西..
$(document).on('change',function(){
相关文章
页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id="...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...