JS基於onclick事件實現單個按鈕的編輯與儲存功能樣本,jsonclick

來源:互聯網
上載者:User

JS基於onclick事件實現單個按鈕的編輯與儲存功能樣本,jsonclick

本文執行個體講述了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>

運行如下:

PS:關於javascript常用事件及相關說明還可參考本站線上工具:

javascript事件與功能說明大全:
http://tools.jb51.net/table/javascript_event

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.