очистить прикрепленный файл type="file"
Здравствуйте
Есть стилизованный инпут type="file", вместо стандартной копки - ссылка <input type="file" name="attach-order" class="attach_order" id="attachorder" title="Прикрепить файл"> <script type="text/javascript"> $(document).ready(function(){ $.fn.customFile = function() { return this.each(function() { var $file = $(this).addClass('customfile'), $wrap = $('<div class="customfile-wrap">'), $link = $('<a href="javascript:void(0);">'+$file[0].title+'</a>'), $label = $('<label class="customfile-upload" for="'+ $file[0].id +'">'+$file[0].title+'</label>'), isIE = /msie/i.test(navigator.userAgent); $file.css({ position: 'absolute', left: '-9999px' }); $wrap.insertAfter($file).append( $file, ( isIE ? $label : $link )); $file.attr('tabIndex', -1); $link.attr('tabIndex', -1); $link.click(function () { $file.focus().click(); }); $file.change(function() { var filename = $file.val().split('\\').pop(); $link.html(( filename ? filename : $file[0].title )); }); }); }; $('input[class=attach_order]').customFile(); }); </script> Хочу сделать так, чтобы была возможность очистить прикрепленный файл кнопкой так очищаю аттач: <input type="submit" id="attach_clear" value="clear"> <script type="text/javascript"> $("#attach_clear").click(function (){ $("#attachorder").val(""); return false; }); </script> Но в tabindex остается название файла, например картинка.jpg вот так выглядит html-код в браузере <input tabindex="-1" style="position: absolute; left: -9999px;" name="attach-order" class="attach_order customfile" title="Прикрепить файл" type="file"> <a tabindex="-1" href="javascript:void(0);">картинка.jpg</a> Пожалуйста, помогите, как сделать, чтобы при очистки аттача, также менялось название прикрепленного файла на текст "Прикрепить файл" вот пример |
единственный способ - заменить <input type="file"> вновь созданным
|
Яростный Меч, а покажите пожалуйста пример
|
Цитата:
<div id="zamena"> <input type="file" name="attach-order" class="attach_order" id="attachorder" title="Прикрепить файл"> </div> <input type="submit" id="attach_clear" value="clear"> если так, то после замены содержимого в диве #zamena в браузере мой стилизованный инпут становится стандартным $("#attach_clear").click(function (){ $("#zamena").html('<input type="file" name="attach-order" class="attach_order" id="attachorder" title="Прикрепить файл">'); }); в этом случае, после замены содержимого в диве #zamena при выборе файла не открывается окно обзора выбора файлов $("#attach_clear").click(function (){ $("#zamena").html('<div class="customfile-wrap"><input tabindex="-1" style="position: absolute; left: -9999px;" name="attach-order" class="attach_order customfile" id="attachorder" title="Прикрепить файл" type="file"><a tabindex="-1" href="javascript:void(0);">Прикрепить файл</a></div>'); }); |
Цитата:
$("#attach_clear").click(function (){ var c = $("#zamena"), f = $("#zamena").find('input')[0].attributes; c.html('<input ' + [].map.call(f, function(a) { return a.name + '="' + a.value + '"' }).join(' ')+' >'); }); |
Глянь сюда.
|
laimas, спасибо, но ваш код не помог, по клику #attach_clear - просто удаляется имя файла, а точнее эта строка:
<a tabindex="-1" href="javascript:void(0);">картинка.jpg</a> сделал по другому, в этой строке для ссылки сделал id: $link = jQnoC55('<a id="zamena" href="javascript:void(0);">'+jQnoC55file[0].title+'</a>'), ну и кнопка: $("#attach_clear").click(function (){ $("#attachorder").val("");//удаляем аттач из "настоящего" инпута $("#zamena").html('Прикрепить файл!');//меняем название прикрепленного файла на текст "Прикрепить файл" return false; }); |
Цитата:
Цитата:
Полная чушь, это свойство только для чтения. |
Цитата:
|
Красиво аж жуть. Форму отправьте.
|
Часовой пояс GMT +3, время: 12:20. |