百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>html5教程> 点击按钮文字酿成input框,点击保留酿成文字的实现
分享文章到:

点击按钮文字酿成input框,点击保留酿成文字的实现

发布时间:09/01 来源:未知 浏览: 关键词:
下面为大家带来一篇点击按钮文字变成input框,点击留存变成文字的实现代码。内容挺不错的,此刻分享给大家,也给大家做个参照 。

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

<!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>XIAOMI5</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框,点击留存变成文字的实现的具体内容,更多请关注百分百源码网其它相关文章!

打赏

打赏

取消

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

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

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

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有150人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板