jQuery and ajax realize the method of modifying content with mouse click

不言
Release: 2018-07-02 16:10:38
Original
1793 people have browsed it

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:

 2 公司介绍 内部栏目 2 
Copy after login

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 = '' ; $(this).parent().append(list_form); //插入 input框 $(".listorder_input").focus(); //自定义一个p 提示修改中 var loading = '

修改中...

'; $(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
Copy after login

The content in ajax.php is simple. It is only used for processing and demonstration, and no data is submitted to the server. The code is as follows:

sleep(1);//延时运行1秒,查看效果用,实际代码中不需要 echo $_POST['listorder'];
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!