源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

JS基于onclick事件实现单个按钮的编辑与保存功能示例

  • 时间:2021-11-24 14:00 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:JS基于onclick事件实现单个按钮的编辑与保存功能示例
本文实例讲述了JS基于onclick事件实现单个按钮的编辑与保存功能。分享给大家供大家参考,具体如下: 该实例可以实现点击同一个按钮实现编辑和保存的功能:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test</title>
</head>
<body>
<span id="xs" >欢迎来到编程素材网!编程素材网提供专业的源码示例与素材下载!</span>
<textarea id="ei" style="display:none;width:300px;">欢迎来到编程素材网!编程素材网提供专业的源码示例与素材下载!</textarea>
<br/>
<input type="button" onclick="edit();" id="btt" name="btt" value="Edit" />
<script type="text/javascript" >
  //Edit content
  function edit(){
    document.getElementById("xs").style.display="none";
    document.getElementById("ei").style.display="";
    var butt=document.getElementById("btt");
    butt.value="Save";
    butt.onclick=function(){
      save();//第二次单击的时候执行这个函数
    };
  }
  //Save content
  function save(){
    var cxs=document.getElementById('xs');
    var ei=document.getElementById("ei");
    var butt=document.getElementById("btt");
    butt.value="Edit";
    ei.style.display="none";
    cxs.innerHTML=ei.value;
    cxs.style.display="";
    butt.onclick=function(){
      edit();//还原第一次单击的时候执行的函数
    };
  }
</script>
</body>
</html>
运行效果图如下: [img]http://files.jb51.net/file_images/article/201702/201721393819601.jpg?201711393839[/img] [b]PS:关于javascript常用事件及相关说明还可参考本站在线工具:[/b] [b]javascript事件与功能说明大全: [/b][url=http://tools.jb51.net/table/javascript_event]http://tools.jb51.net/table/javascript_event[/url] 更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/892.htm]JavaScript事件相关操作与技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/332.htm]JavaScript操作DOM技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/439.htm]JavaScript错误与调试技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/297.htm]JavaScript数据结构与算法技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/281.htm]JavaScript遍历算法与技巧总结[/url]》及《[url=http://www.1sucai.cn/Special/119.htm]JavaScript数学运算用法总结[/url]》 希望本文所述对大家JavaScript程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部