最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery+ajax實(shí)現(xiàn)鼠標(biāo)單擊修改內(nèi)容的方法

 更新時(shí)間:2014年06月27日 15:39:36   投稿:shichen2014  
這篇文章主要介紹了jQuery+ajax實(shí)現(xiàn)鼠標(biāo)單擊修改內(nèi)容的方法,需要的朋友可以參考下

現(xiàn)有表格中的一行的代碼如下所示: 

<tr>
 <td><span class="catid">2</span></td>
 <td>公司介紹</td>
 <td>內(nèi)部欄目</td>
 <td><span class="listorder" title="點(diǎn)擊修改">2</span></td>
</tr>

要實(shí)現(xiàn)鼠標(biāo)單擊修改內(nèi)容思路如下:
 
1、點(diǎn)擊欄目排序欄目中的數(shù)字,獲取同一行的第一列中的內(nèi)容,即欄目id
2、隱藏欄目排序中的數(shù)字
3、在欄目排序列中插入input框,并在input框中顯示欄目排序中的內(nèi)容,并設(shè)置為焦點(diǎn)
4、修改input中的內(nèi)容,失去焦點(diǎn)的時(shí)候提交數(shù)據(jù),用ajax向服務(wù)器傳遞數(shù)據(jù) 方法為post方法
5、提交數(shù)據(jù)的時(shí)候,友好提示修改中。。。 或者等待圖片
6、返回成功信息 ,重新顯示修改后的內(nèi)容 去掉input框

實(shí)現(xiàn)這一功能的jquery核心代碼如下:

$('.listorder').click(function(e){
 var catid = $(this).parent().siblings("td:eq(0)").text();//獲取同一行上 第一列中的id值
 var listorder_now_text = $(this).text();//獲取listorder中的內(nèi)容 先保存起來(lái)
 $(this).text("");//設(shè)置內(nèi)容為空
 var list_form = '<input type="text"  value="'+listorder_now_text+'" size=2 class="listorder_input" />' ;
 $(this).parent().append(list_form); //插入 input框
 $(".listorder_input").focus();
//自定義一個(gè)div 提示修改中
 var loading = '<div id="loading"><img src="img/loading.gif" alt="修改中..."/></div>';
 $(this).parent().append(loading);
 $('#loading')
  .css({
   "color" : "red" ,
   "display" : "none"
  })
//定義ajax的全局事件
 $(this).ajaxStart(function(){
  $('#loading').show();
 })
 $(this).ajaxStop(function(){
  $('#loading').remove();
 })
 $(".listorder_input").blur(function(){
  var thislist = $(this).siblings(); //取得同級(jí)的標(biāo)簽 即 修改后需要顯示的 listorder
  $.post("ajax.php",{
  action : "mod_listorder",
  catid : catid ,
  listorder : $(this).attr("value")
  } , function(data, textStatus){
    $(thislist).text(data);
    }
  );//end .post
  $(this).remove();
 })//end function blur
})// end function click

ajax.php中內(nèi)容就簡(jiǎn)單了,這里只做處理做演示用,并沒(méi)有向服務(wù)器提交數(shù)據(jù),代碼如下:

sleep(1);//延時(shí)運(yùn)行1秒,查看效果用,實(shí)際代碼中不需要
echo $_POST['listorder'];

相關(guān)文章

最新評(píng)論

蒙阴县| 孟村| 当阳市| 榕江县| 南投市| 承德县| 进贤县| 封丘县| 延吉市| 万年县| 承德市| 乡城县| 建阳市| 正定县| 江孜县| 桂东县| 阿拉善右旗| 台东市| 兴山县| 舟山市| 荣昌县| 桦南县| 柞水县| 大田县| 新干县| 临湘市| 福贡县| 丹凤县| 长治市| 泗水县| 宜章县| 贡觉县| 普定县| 雷山县| 大竹县| 石阡县| 孝感市| 闽侯县| 上犹县| 岢岚县| 类乌齐县|