点击按钮文字变成input框,点击保存变成文字的实现


本文摘自PHP中文网,作者不言,侵删。

下面为大家带来一篇点击按钮文字变成input框,点击保存变成文字的实现代码。内容挺不错的,现在分享给大家,也给大家做个参考。

点击按钮文字变成input框,点击保存变成文字的实现代码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

<!DOCTYPE html>

<html lang="en">

<head>

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta charset="utf-8">

  <title>点击按钮文字变成input框,点击保存变成文字</title>

  <style type="text/css">

  table{ text-align: center; font-size: 14px;}  

  table>thead>tr>th{ font-weight: normal;}  

  .text-right{ padding-right:73px; text-align: right;}  

  .text{ width: 50px; height: 30px; border: 1px solid #ddd; text-align: center;}  

  </style>

  <script type="text/javascript" src="js/jquery.min.js"></script>

</head>

<body>

  <table>

    <thead>

      <tr>

        <th width="400">品名</th>

        <th width="200">件数</th>

      </tr>

    </thead>

    <tbody>

      <tr height="50">

        <td>iPhone6s</td>

        <td class="edit">2</td>

      </tr>

      <tr height="50">

        <td>小米5</td>

        <td class="edit">5</td>

      </tr>

    </tbody>

    <tfoot>

      <tr>

        <td colspan="2" class="text-right">

          <button type="button" class="btn" onclick="change(this)">修改</button>

        </td>

      </tr>

    </tfoot>

  </table>

<script type="text/javascript">

function change(obj){  

  var xg=$(obj).html();  

  if(xg=='修改'){  

    $('.edit').each(function(){  

      var old=$(this).html();  

      $(this).html("<input type='text' name='editname' class='text' value="+old+" >");  

    })  

    $(obj).html('保存');  

  }else if(xg=='保存'){  

    $('input[name=editname]').each(function(){  

      var old=$(this).html();  

      var newfont=$(this).parent('td').parent('tr').children().find('input').val();  

      $(this).parent('td').html(newfont);  

    })  

    $(obj).html('修改');  

  }  

}  

</script>

</body>

</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

关于移动 web 端屏幕适配(rem)的介绍

如何使用HTML在两个div标签中间画一条竖线

以上就是点击按钮文字变成input框,点击保存变成文字的实现的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

css怎么设置不能选中文字

html中有哪些标记文字注释的符号

css3怎么让文字垂直居中显示

怎样修改输入框的默认文字颜色

分享文字溢出隐藏实例

css如何实现文字外发光效果

css中怎么把文字加粗

html怎么使按钮不可用

html怎么让文字在图片表面

dreamweaver设计简单的导航按钮方法教程

更多相关阅读请进入《按钮》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...