日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > web前端 > jscript > 用js實現ajax無刷新修改圖片標題和描述

用js實現ajax無刷新修改圖片標題和描述

來源:程序員人生   發布時間:2014-04-03 12:16:11 閱讀次數:3589次

 

以下為引用的內容:
用js實現ajax無刷新修改圖片標題和描述的前臺代碼;
一個html文件,內容如下:
<!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=="點擊添加照片描述") 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("描述字數最多只能是2000個漢字!請重新輸入。");
  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'>點擊添加圖片描述</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=='點擊添加照片描述'){
  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);'>點擊添加照片描述<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>";
 }
}
//修改標題
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=="點擊添加照片名稱") 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'>點擊添加照片名稱</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=='點擊添加照片名稱') {
  tit.innerHTML="<i style='color: #888' onclick='initTit("+photoID+");' onmouseover='ch(this);' onmouseout='res(this);'>點擊添加照片名稱</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="點擊添加照片名稱" />
     <div title="點擊修改照片名稱" id="tit" onclick="initTit('1');" onmouseover="ch(this);" onmouseout="res(this);" style="width: 320px; word-wrap: break-word;">
     <i style="color: #888;">點擊添加照片名稱</i>
     </div>
<br/>
   <div><div title="點擊修改照片描述" id="txto" style="width: 820px; word-wrap: break-word;" onclick="initDesc('1');" onmouseover="ch(this);" onmouseout="res(this);"><i style="color: #888;">點擊添加照片描述"</i></div>
  </div>
  <input type="hidden" id="hid" value="點擊添加照片描述" />
   </div>
  </div>
</body>
</html>


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 国产精品美女一区二区三区 | 91免费在线播放 | 九九热在线视频观看这里只有精品 | 久久久www成人免费无遮挡大片 | 高清一区二区三区四区 | 黄色大片网站 | 成人影院免费观看 | 99精品在线观看 | 国产成人免费视频 | 黄色电影网站在线观看 | 91短视频黄 | 一级黄色性视频 | 秋霞色| 日韩欧美影院 | 天堂网2018 | 日韩午夜在线视频 | 婷婷欧美 | 一区二区三区免费观看 | 97精品欧美一区二区三区 | 国产精品视频yy9099 | 国产成人精品一区二区三区四区 | 久草在线在线精品观看 | 久久精品国产久精国产 | 成人一区二区三区四区 | 亚洲日韩中文字幕 | 可以看黄色的网站 | 亚洲视频欧美视频 | 国产精品免费一区二区三区都可以 | 免费黄色高清视频 | 插综合网 | 日韩欧美电影在线观看 | 国产一区二区在线看 | 久久国产精品区 | 色精品 | 亚洲成人免费在线 | 欧美日韩精选 | 午夜性刺激免费看视频 | 在线观看www | 亚洲 欧美 制服 | 一区二区三区国产在线 | 91精品国产综合久久精品图片 |