欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

点击按钮文字变成input框,点击保存变成文字的实现代码_HTML/Xhtml_网页制作

程序员文章站 2022-04-14 08:20:08
...
点击按钮文字变成input框,点击保存变成文字的实现代码
XML/HTML Code复制内容到剪贴板
  1. /span>>
  2. html lang="en">
  3. head>
  4.   meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5.   meta charset="utf-8">
  6.   title>点击按钮文字变成input框,点击保存变成文字title>
  7.   style type="text/css">
  8.   table{ text-align: center; font-size: 14px;}
  9.   table>thead>tr>th{ font-weight: normal;}
  10.   .text-right{ padding-right:73px; text-align: right;}
  11.   .text{ width: 50px; height: 30px; border: 1px solid #ddd; text-align: center;}
  12.   style>
  13.   script type="text/javascript" src="js/jquery.min.js">script>
  14. head>
  15. body>
  16.   table>
  17.     thead>
  18.       tr>
  19.         th width="400">品名th>
  20.         th width="200">件数th>
  21.       tr>
  22.     thead>
  23.     tbody>
  24.       tr height="50">
  25.         td>iPhone6std>
  26.         td class="edit">2td>
  27.       tr>
  28.       tr height="50">
  29.         td>小米5td>
  30.         td class="edit">5td>
  31.       tr>
  32.     tbody>
  33.     tfoot>
  34.       tr>
  35.         td colspan="2" class="text-right">
  36.           button type="button" class="btn" onclick="change(this)">修改button>
  37.         td>
  38.       tr>
  39.     tfoot>
  40.   table>
  41. script type="text/javascript">
  42. function change(obj){
  43.   var xg=$(obj).html();
  44.   if(xg=='修改'){
  45.     $('.edit').each(function(){
  46.       var old=$(this).html();
  47.       $(this).html("input type='text' name='editname' class='text' value="+old+" >");
  48.     })
  49.     $(obj).html('保存');
  50.   }else if(xg=='保存'){
  51.     $('input[name=editname]').each(function(){
  52.       var old=$(this).html();
  53.       var newfont=$(this).parent('td').parent('tr').children().find('input').val();
  54.       $(this).parent('td').html(newfont);
  55.     })
  56.     $(obj).html('修改');
  57.   }
  58. }
  59. script>
  60. body>
  61. html>

以上这篇点击按钮文字变成input框,点击保存变成文字的实现代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

原文地址:http://www.cnblogs.com/yuxiaoqi912/p/5470354.html