多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > web前端 > jscript > 用js實(shí)現(xiàn)ajax無刷新修改圖片標(biāo)題和描述

用js實(shí)現(xiàn)ajax無刷新修改圖片標(biāo)題和描述

來源:程序員人生   發(fā)布時(shí)間:2014-04-03 12:16:11 閱讀次數(shù):3581次

 

以下為引用的內(nèi)容:
用js實(shí)現(xiàn)ajax無刷新修改圖片標(biāo)題和描述的前臺(tái)代碼;
一個(gè)html文件,內(nèi)容如下:
<!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=gb2312" />
<title>ajax修改</title>
<script language="javascript">
// IE support
if (window.ActiveXObject && !window.XMLHttpRequest) {
  window.XMLHttpRequest=function() {
     return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
 };
}
//修改描述
function update(photoID, descvalue) {
 var req=new XMLHttpRequest();
 if (req) {
     req.onreadystatechange=function(){
        if (req.readyState==4 && req.status==200) {
           if (req.responseText!="") alert(req.responseText);
        }
  }
 }
    var act= document.getElementById("path").value+"/AjaxCtrl";
    req.open('POST', act);
    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 req.send("page=UpdatePhotoDescPage&photoID="+photo_id+"&desc="+descvalue);
}
 
function initDesc(photoID){
 var desc=document.getElementById("txto");
 desc.onclick="";
 desc.onmouseover="";
 var str = document.getElementById('hid').value;
 if(str=="點(diǎn)擊添加照片描述") str="";
 desc.innerHTML="<textarea id='txt' class='highlight' style='margin-top: 0px; font-size: 14px; margin-bottom: 0px; width: 820px' rows='5'>"+str.replace(/<br>/g,'')+"</textarea><br><input type='button' value='保存' onclick='getvalue("+photoID+");' />&nbsp;&nbsp;<input type='button' value='取消' onclick='resetDescHTML("+photoID+");' />";
}
function getvalue(photoID){
 desctxt=document.getElementById("txt");
 var desc=document.getElementById("txto");
 var descvalue=desctxt.value.replace(/(^s*)|(s*$)/g, '');
 var str=descvalue;
 if(str.length > 2000){
  alert("描述字?jǐn)?shù)最多只能是2000個(gè)漢字!請重新輸入。");
  return;
 }
 desc.innerHTML="正在保存中。。。。。。";
 if(str==''){
  update(photoID,'');
  document.getElementById('hid').value='';
  desc.innerHTML="<div id='sp' onclick='initDesc("+photoID+");' style='width: 320px' onmouseover='ch(this);' onmouseout='res(this);'><i style='color: #888; width: 240px'>點(diǎn)擊添加圖片描述</i></div>";
 } else {
  update(photoID,str);
  document.getElementById('hid').value = descvalue;
  desc.innerHTML="<div id='sp' onclick='initDesc("+photoID+");' style='width: 320px; word-wrap: break-word;' onmouseover='ch(this);' onmouseout='res(this);'>"+filtertxtd(document.getElementById('hid').value)+"</div>";
 }
}
function resetDescHTML(photoID){
 var desc=document.getElementById("txto");
 if(document.getElementById('hid').value=='' || document.getElementById('hid').value=='點(diǎn)擊添加照片描述'){
  desc.innerHTML="<div id='sp' onclick='initDesc("+photoID+");' style='width: 320px' onmouseover='ch(this);' onmouseout='res(this);'><i style='color: #888; width: 320px' onmouseover='res(this);' onmouseout='ch(this);'>點(diǎn)擊添加照片描述<i></div>";
 } else {
  desc.innerHTML="<div id='sp' onclick='initDesc("+photoID+");' style='margin-top: 0px; font-size: 14px; margin-bottom: 0px; width: 320px; word-wrap: break-word;' onmouseover='ch(this);' onmouseout='res(this);'>"+filtertxtd(document.getElementById('hid').value)+"</div>";
 }
}
//修改標(biāo)題
function updateTit(photoID, titvalue) {
 var req=new XMLHttpRequest();
 if (req) {
     req.onreadystatechange=function(){
   if (req.readyState==4 && req.status==200) {
      if (req.responseText!="") alert(req.responseText);
   }
  }
 }
    var act= document.getElementById("path").value+"/AjaxCtrl";
    req.open('POST', act);
    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 req.send("page=UpdatePhotoTitlePage&photoID="+photo_id+"&title="+titvalue);
}
function initTit(photoID) { 
 var tit=document.getElementById("tit");
 tit.onclick="";
 tit.onmouseover="";
 var str = document.getElementById('hidTit').value;
 if(str=="點(diǎn)擊添加照片名稱") str="";
 tit.innerHTML="<input type='text' id='txtTit' class='highlight' style='margin-top: 0px; font-size: 14px; margin-bottom: 0px; width: 320px' value='"
    + str + "'maxlength='50' /><br><input type='button' value='保存' onclick='getTit("+photoID+");' />&nbsp;&nbsp;<input type='button' value='取消' onclick='resetTitHTML("+photoID+");' />";
}
function getTit(photoID) {
 var txtTit=document.getElementById("txtTit");
 var tit=document.getElementById("tit");
 var titvalue=txtTit.value.replace(/(^s*)|(s*$)/g, '');
 tit.innerHTML="正在保存中。。。。。。";
 if(titvalue==''){
  updateTit(photoID,'');
  document.getElementById("hidTit").value='';
  tit.innerHTML="<div id='sp' onclick='initTit("+photoID+");' style='width: 320px' onmouseover='ch(this);' onmouseout='res(this);'><i style='color: #888'>點(diǎn)擊添加照片名稱</i></div>";
 } else {
  updateTit(photoID, titvalue);
  document.getElementById("hidTit"+idx).value=filtertxtd(titvalue);
  tit.innerHTML="<div id='sp' onclick='initTit("+photoID+");' style='width: 320px' onmouseover='ch(this);' onmouseout='res(this);'><h4 id='title_div44177575' style='margin-top: 0px; font-size: 14px; margin-bottom: 0px; width: 320px'>"+document.getElementById("hidTit").value+"</h4></div>";
 }
}
function resetTitHTML(photoID) {
 var tit=document.getElementById("tit");
 if(document.getElementById('hidTit').value=='' || document.getElementById('hidTit').value=='點(diǎn)擊添加照片名稱') {
  tit.innerHTML="<i style='color: #888' onclick='initTit("+photoID+");' onmouseover='ch(this);' onmouseout='res(this);'>點(diǎn)擊添加照片名稱</i>";
  tit.onmouseover="ch(this);";
 } else {
  tit.innerHTML="<div id='sp' onclick='initTit("+photoID+");' onmouseover='ch(this);' onmouseout='res(this);' style='width: 320px; word-wrap: break-word;'><h4 id='title_div44177575' style='margin-top: 0px; font-size: 14px; margin-bottom: 0px; width: 320px'>"+filtertxtd(document.getElementById('hidTit').value)+"</h4></div>";
 }
}
function ch(activeX){
 activeX.style.background="#ffc";
}
function res(activeX){
 activeX.style.background="#fff";
}
function filtertxtd(str){
 var filterStr=str.replace(/(^s*)|(s*$)/g, '').replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(//g,"<br>");
 return filterStr;
}
</script>
</head>
<body>
<input type="hidden" id="hidTit" value="點(diǎn)擊添加照片名稱" />
     <div title="點(diǎn)擊修改照片名稱" id="tit" onclick="initTit('1');" onmouseover="ch(this);" onmouseout="res(this);" style="width: 320px; word-wrap: break-word;">
     <i style="color: #888;">點(diǎn)擊添加照片名稱</i>
     </div>
<br/>
   <div><div title="點(diǎn)擊修改照片描述" id="txto" style="width: 820px; word-wrap: break-word;" onclick="initDesc('1');" onmouseover="ch(this);" onmouseout="res(this);"><i style="color: #888;">點(diǎn)擊添加照片描述"</i></div>
  </div>
  <input type="hidden" id="hid" value="點(diǎn)擊添加照片描述" />
   </div>
  </div>
</body>
</html>


生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 亚洲一区二区三区影院 | 日韩在线a视频免费播放 | 亚洲欧美日本欧美在线播放污 | 羞羞视频免费观看网站 | 日本欧美一区 | 国产精品v欧美精品v日韩精品 | 欧美成人性色大片在线观看 | 日本免费一级片 | 欧美色人阁 | www日本www| 亚洲视频一区二区在线观看 | h国产视频 | 国产亚洲制服 | 毛片免费毛片一级jjj毛片 | 亚洲国产成人精彩精品 | 国产成人免费在线视频 | 超乳w真性中出し冲田杏梨101 | 美女又黄又免费 | 国产尤物在线观看 | 国产精品久久久久久久免费大片 | 欧美淫| 久久亚洲国产成人影院 | 亚洲情区 | 男人天堂亚洲天堂 | 亚洲欧美在线看 | 最近中文字幕经典版在线 | 久久国产区 | 欧洲乱码专区一区二区三区四区 | 东方伊人免费在线观看 | 国产女人的一级毛片视频 | 亚洲午夜国产精品无卡 | 素人259luxu在线观看暴露 | 欧美3p在线观看一区二区三区 | 欧美三级视频 | 日韩精品一区二区三区中文字幕 | 三级在线观看视频 | 久久精品一区二区三区日韩 | 亚洲欧美成人综合在线 | 欧洲免费无线码一二区 | 男女www视频| 无遮挡在线视频 |