Показать сообщение отдельно
  #1 (permalink)  
Старый 18.05.2016, 22:42
Аспирант
Отправить личное сообщение для rodiony4 Посмотреть профиль Найти все сообщения от rodiony4
 
Регистрация: 26.10.2015
Сообщений: 97

очистить прикрепленный файл 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>

Пожалуйста, помогите, как сделать, чтобы при очистки аттача, также менялось название прикрепленного файла на текст "Прикрепить файл"
вот пример

Последний раз редактировалось rodiony4, 18.05.2016 в 22:54.
Ответить с цитированием