jquery文件操作:提取文件名,将文件路径中的反斜杠转换为斜杠

时间:2022-11-25 22:23:51
	if(n.attachment != "")
	{
		var PostionOfLastSlash = 0;
		var iIndex = 0 ;
		var NameIndex = 0;
		var NameString = "";
		var AttachMentString = n.attachment;
		var AttachMentNewString = "";
	
		for(;iIndex < AttachMentString.length;iIndex++)																		
		{
			if(AttachMentString[iIndex] == '\\')
			{
				PostionOfLastSlash = iIndex;

			}
	
		}
	
		//alert("AttachMentString[PostionOfLastSlash+1]:"+AttachMentString[PostionOfLastSlash+1]+" PostionOfLastSlash:"+PostionOfLastSlash);
		
		NameString = AttachMentString.substr(PostionOfLastSlash+1,AttachMentString.length);
		for(iIndex = 0;iIndex < AttachMentString.split("\\").length ;iIndex++)
		{
			if(iIndex == AttachMentString.split("\\").length-1) //结尾时没有"/"
			{
				AttachMentNewString += AttachMentString.split("\\")[iIndex];
			}
			else
			{
				AttachMentNewString += AttachMentString.split("\\")[iIndex]+"/";
			}
		}
		//alert("NameString:"+NameString+"  AttachMentNewString:"+AttachMentNewString);
		AttachMent = '下载附件:<a style = "cursor:pointer;" onclick="download(\''+AttachMentNewString+'\',\''+NameString+'\');return 0;">'+NameString+'</a>';
	}
	else
	{

		AttachMent = "";
	}