日期:2014-05-16 浏览次数:20440 次
var str='xxx.png';
var d=/\.[^\.]+$/.exec(str);
alert(d);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<input type="file" id="fileId" onchange="selectFile(this)" />
</body>
<script type="text/javascript">
function selectFile(input) {
var fileName = input.value;
if(fileName.length > 1 && fileName ) {
var ldot = fileName.lastIndexOf(".");
var type = fileName.substring(ldot + 1);
if(type != "img") {
alert(type);
//清除当前所选文件
input.outerHTML=input.outerHTML.replace(/(value=\").+\"/i,"$1\"");
}
}
}
</script>
</html>