国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery+ajax實現鼠標單擊修改內容的方法

2019-11-20 14:23:42
字體:
來源:轉載
供稿:網友

現有表格中的一行的代碼如下所示: 

<tr> <td><span class="catid">2</span></td> <td>公司介紹</td> <td>內部欄目</td> <td><span class="listorder" title="點擊修改">2</span></td></tr>

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

實現這一功能的jquery核心代碼如下:

$('.listorder').click(function(e){ var catid = $(this).parent().siblings("td:eq(0)").text();//獲取同一行上 第一列中的id值 var listorder_now_text = $(this).text();//獲取listorder中的內容 先保存起來 $(this).text("");//設置內容為空 var list_form = '<input type="text"  value="'+listorder_now_text+'" size=2 class="listorder_input" />' ; $(this).parent().append(list_form); //插入 input框 $(".listorder_input").focus();//自定義一個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(); //取得同級的標簽 即 修改后需要顯示的 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中內容就簡單了,這里只做處理做演示用,并沒有向服務器提交數據,代碼如下:

sleep(1);//延時運行1秒,查看效果用,實際代碼中不需要echo $_POST['listorder'];
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉义县| 和顺县| 漳州市| 沈丘县| 哈巴河县| 新干县| 盘锦市| 三台县| 明星| 丹巴县| 新乐市| 曲沃县| 江山市| 余干县| 普宁市| 建始县| 临颍县| 台中县| 香格里拉县| 贵定县| 青海省| 炉霍县| 海南省| 洛南县| 福泉市| 彭泽县| 三都| 灵川县| 嘉鱼县| 洮南市| 黄陵县| 吉林省| 疏勒县| 慈利县| 南部县| 丁青县| 莎车县| 施秉县| 扎囊县| 钟祥市| 湘潭市|