> 웹 프론트엔드 > JS 튜토리얼 > jQuery는 버튼 텍스트를 클릭하면 입력 상자가 되고 저장을 클릭하면 text_jquery로 바뀌는 것을 인식합니다.

jQuery는 버튼 텍스트를 클릭하면 입력 상자가 되고 저장을 클릭하면 text_jquery로 바뀌는 것을 인식합니다.

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
풀어 주다: 2016-05-16 09:00:17
원래의
2588명이 탐색했습니다.

더 이상 고민하지 않고 코드만 게시해 드리겠습니다.

구체적인 코드는 다음과 같습니다.

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>

로그인 후 복사

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿