本文實例講述了PHP+jQuery實現即點即改功能。分享給大家供大家參考,具體如下:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>即點即改</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script></head><body><?php$con = array( array("id"=>1,"姓名"=>"張三","性別"=>"女"), array("id"=>2,"姓名"=>"李四","性別"=>"男"), array("id"=>3,"姓名"=>"王五","性別"=>"男")); // print_r($con);die;?> <table align="center" border="1"> <?php foreach ($con as $key => $v): ?> <tr pid="<?= $v['id'];?>"> <td><span class="up" style="cursor:pointer;"><?= $v['姓名'];?></span></td> <td><?= $v['性別'];?></td> </tr> <?php endforeach; ?> </table></body></html><script> //即點即改 $(document).on("click",".up",function(){ var content = $(this).text(); //獲取到當前點擊對象的值 var pid = $(this).parents("tr").attr('pid'); //通過attr 獲取到設置的屬性(pid) //當點擊修改文字時 變成文本框并且獲取到原值(content) $(this).parent().html("<input type='text' class='fo' value='" + content + "'/>"); $(".fo").focus(); //光標 $(".fo").blur(function(){ //獲取到修改后的值 var val = $(".fo").val(); // /* 將所有修改信息傳到后端 */ $(this).parent().html("<span class='up' style='cursor:pointer;'>"+val+"</span>"); }) })</script>
運行結果:
希望本文所述對大家PHP程序設計有所幫助。
新聞熱點
疑難解答
圖片精選