image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png

    • Proxy 代理好处的源码

    不会影响到方法原来的自己使用的是其相应的代理,在示例中就是去除了 “冒泡” 的影响

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <title>Proxy</title>
    6. <link href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
    7. </head>
    8. <body>
    9. <table class="table table-bordered" id="table-test">
    10. <tr>
    11. <th>姓名</th>
    12. <th>成绩</th>
    13. </tr>
    14. <tr>
    15. <td>小明</td>
    16. <td>47</td>
    17. </tr>
    18. <tr>
    19. <td>小红</td>
    20. <td>76</td>
    21. </tr>
    22. </table>
    23. <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    24. <script>
    25. // $('#table-test tr td').click(function(e) {
    26. // var _value = $(this).html();
    27. // if($(this).find('input').length == 0){
    28. // var s = '<input type="text" value="'+ _value+'">';
    29. // $(this).html(s);
    30. // }
    31. // });
    32. // //给 input 绑定事件
    33. // $('#table-test tr td').on('keyup','input',function(e){
    34. // if(e.keyCode == 13){
    35. // var _input = $(e.target);
    36. // _input.parent('td').html(_input.val());
    37. // }
    38. // });
    39. var index = {
    40. init:function(){
    41. this.render();
    42. this.bind();
    43. },
    44. render:function(){
    45. this.mytd = $('#table-test tr td');
    46. },
    47. bind:function(){
    48. var me = this;
    49. me.mytd.click($.proxy(me._do,this));
    50. },
    51. _do:function(e){
    52. var s = $(e.target);
    53. var _value = s.html();
    54. var _input = '<input type="text" value="'+ _value+'">';
    55. s.html(_input);
    56. }
    57. }
    58. index.init();
    59. </script>
    60. </body>
    61. </html>

    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png
    image.png