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


本文摘自PHP中文网,作者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

62

63

64

65

66

<!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中文网其它相关文章!

阅读剩余部分

相关阅读 >>

html代码制作滚动文字

html怎么设置文字的间距

bootstrap中怎么设置按钮位置

怎样用css隐藏图片背景的文字内容

h5实现多图片预览上传及点击可拖拽控件

css给文字添加描边的方法是什么

css如何让图片和文字垂直居中对齐

css如何让文字有阴影

html中用href 实现点击链接弹出文件下载对话框

css怎么去掉按钮的边框

更多相关阅读请进入《文字》频道 >>




打赏

取消

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

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

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

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

评论

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