file美化插件

<h2>首先你需要结合seajs使用</h2>
<pre>
<h5>这是插件代码块</h5>
<code>
define(function(require, exports, module) {
require('subject');
var file = function(option){
op=$.extend({
},option);
if(op.$inputFile){
$(op.$textHtml).insertBefore(op.$inputFile);
$(op.$butHtml).insertBefore(op.$inputFile);
};
var $upFileTxt = $(op.$textHtml).attr('class');
$("."+$upFileTxt+"").css(op.css);
op.$inputFile.css(op.fileCss);//设定源生的file的样式
op.$inputFile.change(function(){
//获取file变化后的value值
var $fileVal = $(this).val();
//截取路径,只显示文件名
var $sub=$fileVal.substring($fileVal.lastIndexOf('\')+1);
//把file的value值赋给属性为text并且是特定class值的input
$("."+$upFileTxt+"").html($sub).val($sub);
});
};
return{
file:file
}
});
</code></pre>

<pre>
<h5>这里是根据你的业务需求调用代码块</h5>
<code>
$file.file({
$inputFile: $('input:file[class=file]'),
$butHtml: '<input type="button" class="upFileBtn" value="上传附件" />',
$textHtml: '<div class="upFileTxt"></div>',
css: {
width:573,
height:32,
zIndex:0
},
fileCss: {
width:675,
height:34,
left:122
}
});
</code>
</pre>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容