This article mainly introduces the method of jQuery ajax to implement mouse click to modify content. Friends who need it can refer to
The code of a row in the existing table is as follows:
<tr> <td><span class="catid">2</span></td> <td>公司介绍</td> <td>内部栏目</td> <td><span class="listorder" title="点击修改">2</span></td> </tr>
The idea to modify the content with a mouse click is as follows:
1. Click the number in the column sorting column to get the first column of the same row The content, that is, the column id
2, hide the number in the column sorting
3, insert the input box in the column sorting column, and display the content in the column sorting in the input box, and set it as the focus
4. Modify the content in the input, submit the data when the focus is lost, and use ajax to transfer data to the server using the post method
5. When submitting the data, a friendly prompt will appear that is being modified. . . Or wait for the picture
6, return the success message, redisplay the modified content and remove the input box
The jquery core code to implement this function is as follows:
##
$('.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(); //自定义一个p 提示修改中 var loading = '<p id="loading"><img src="img/loading.gif" alt="修改中..."/></p>'; $(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
sleep(1);//延时运行1秒,查看效果用,实际代码中不需要 echo $_POST['listorder'];
jquery realizes the effect of horizontal scrolling of pictures
jQuery and canvas realize the flat throwing and color of the sphere Dynamic transformation effect
The above is the detailed content of jQuery and ajax realize the method of modifying content with mouse click. For more information, please follow other related articles on the PHP Chinese website!