Javascript 代码片段
1、避免汉字出现乱码
<script type="text/javascript" charset="gb2312" src="AutoSize.js"></script>
2、图片上传时验证文件名
function ValidateFileName(fileName)
{
var validated;
if (fileName.length == 0)
{
validated = false;
alert("请选择要上传的图片!");
}
else
{
validated = /^[A-Z]:\\{1,2}[^/:\*\?<>\|]+\.(jpg|gif|png|bmp)$/i.test(fileName);
if(!validated) alert("只能上传 jpg/gif/png/bmp 格式的图片!");
}
return validated;
}
{
var validated;
if (fileName.length == 0)
{
validated = false;
alert("请选择要上传的图片!");
}
else
{
validated = /^[A-Z]:\\{1,2}[^/:\*\?<>\|]+\.(jpg|gif|png|bmp)$/i.test(fileName);
if(!validated) alert("只能上传 jpg/gif/png/bmp 格式的图片!");
}
return validated;
}