📄 up_pic_test.js
字号:
var xmlRequest_uppic = '';
function submitForm()
{//实现提交功能
alert('in up_pic_test.js submitForm()');
var url = submitEnable();
xmlRequest_uppic = createXMLHttpRequest();
//xmlRequest_uppic.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlRequest_uppic.open('post',url);
xmlRequest_uppic.onreadystatechange = upPicResponse;
xmlRequest_uppic.send(null);
}
var iCount = 0;
function upPicResponse()
{
alert('in upPicResponse ' + iCount++);
alert(xmlRequest_uppic.readyState);
if (xmlRequest_uppic.readyState == 4)
{
alert('in state == 2 ' + xmlRequest_uppic.status);
if (xmlRequest_uppic.status == 200)
{
alert('status');
document.getElementById('message_up_pic').innerHTML = 'ok';
}
}
}
function submitEnable()
{
var photoType = document.getElementById('photoType').value;
var photoName = document.getElementById('photoName').value;
var up_file = document.getElementById('up_file').value;
if ( !isNotNull(photoType))
{
return false;
}
if ( !isNotNull(photoName))
{
return false;
}
if ( !isNotNull(up_file))
{
return false;
}
var url = "doUpload.pho?photoTyp="+photoType+"&photoName="+photoName+"&up_file="+up_file;
// var content = '';
return url;
}
//begin showImg
function showImg()
{
if (!checkImg(document.getElementById('up_file').value))
{
//alert('图片格式不识别.请选择gif和jpg格式的图片');//错误出
document.getElementById('up_form').reset();
return false;
}
document.getElementById('img_div').style.display='block'
document.getElementById('img_show').src= document.getElementById('up_file').value;
return true;
}
function resetAll()
{//清空所有文本框以及与之有关的图片显示
if(!confirm('确认要全部清空吗?'))
{
return false;
}
document.getElementById('up_form').reset();
document.getElementById('img_div').style.display='none';
document.getElementById('img_show').src= '';
}
function checkImg(str)
{
var index = str.lastIndexOf('.') ;
if (index > -1)
{
var sub = str.substring(index);
return match(sub);
}
return match(str);
}
function match(str)
{
str =str.toLowerCase();
var matchStr = new Array(3);
matchStr[0]='.gif';
matchStr[1]='.jpg';
for (var i=0;i<matchStr.length;i++)
{
if (matchStr[i] == str)
{
return true;
}
}
return false;
}
//end checkImg() all
function isNotNull(str)
{ //如果str是非空字符串则返回true;
if (typeof(str) == 'undefined') return false;
if (typeof(str) != 'string')return false;
if (str =='') return false;
if (str.length < 1) return false;
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -