关于 input type=file 事件屏蔽

·工作中遇到了一个有趣的问题:

<form>

 <em>+</em>

  <input  type=file ></input>

 <./form>

 

css中使得input框覆盖了+号; 当点击+号时平常的弹出选择文件,选到文件了现实文件名,+号变成-号

再按inpu框时 清楚已经选择的 文件

 

 

$(document).ready(function() {
	
var fileType = $('input[name="fileType"]').val();
var title=fileType == 'img' ? "插入图片":"添加附件";
inputChange(title);
	
function inputChange(title){
	$('input[type="file"]').change(function() {
		var ff = $(this).parent().parent();
		var fileName = $(this).val();
		if(fileName.indexOf("\\") > -1) {
			var startIndex = fileName.lastIndexOf("\\");
			fileName = fileName.substring(startIndex + 1, fileName.length);
		}
	    ff.attr("class","btn_delPic");
	    ff.children(':first').html("<em>-</em>" + fileName);
		$(this).html(fileName);
		inputClick($(this), title);

	});
   }
	
	function inputClick(obj, title){
		obj.click(function(){
			var name = obj.attr("name");
			obj.parent().parent().children(':first').html("<em>+</em>" + title);
			obj.parent().parent().attr("class","btn_addPic");
			obj.parent().html('<input class="filePrew" name='+name+' type="file"/>');
			inputChange(title);
			return false; 
		});
		
	}

});

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值