【www.gdgbn.com--中文酷站】


tolowercase() 方法用于把字符串转换为小写。

语法
stringobject.tolowercase()返回值
一个新的字符串,在其中 stringobject 的所有大写字符全部被转换为了小写字符


lastindexof() 方法可返回一个指定的字符串值最后出现的位置,在一个字符串中的指定位置从后向前搜索。

语法
stringobject.lastindexof(searchvalue,fromindex)参数 描述
searchvalue 必需。规定需检索的字符串值。
fromindex 可选的整数参数。规定在字符串中开始检索的位置。它的合法取值是 0 到 stringobject.length - 1。如省略该参数,则将从字符串的最后一个字符处开始检索。

返回值
如果在 stringobject 中的 fromindex 位置之前存在 searchvalue,则返回的是出现的最后一个 searchvalue 的位置。

 

下面看个利用tolowercase lastindexof限制只能上传图片代码

function checkphoto(fnupload)
{
var filename = fnupload.value;
alert(filename);
var mime = filename.tolowercase().substr(filename.lastindexof("."));
if(mime!=".jpg")
{
alert("请选择jpg格式的照片上传");
fnupload.outerhtml=fnupload.outerhtml;
}
}

本文来源:http://www.gdgbn.com/kuzhan/28356/