1. 程式人生 > >基於閉包實現的顯示與隱藏

基於閉包實現的顯示與隱藏

body this float type color next() onclick upd otc

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6     </head>
 7     <body>
 8         <div class="binds">
 9             <div class="phonebind">
10                 <h3>手機綁定</h3>
11
<p>當前手機號碼:<span id="oldPhone">12345678</span> 12 <input type="button" class="btnInput" id="rehindPhone" value="重新綁定" /> 13 </p> 14 <div class="updatetelwrap hidden"> 15 <div class="newphonewrap"> 16
<label>新手機號碼<em>*</em></label> 17 <input type="text" class="formatText" id="newPhone" /> 18 </div> 19 <div class="identifywrap"> 20 <label>短信驗證碼<em>*</em></label> 21
<input type="text" class="inputcode" /> 22 <p><input type="button" value="獲取短信驗證碼" class="bindbtn" 23 id="newphonebind" style="float: left;" onclick="javascript:bindPhone();" /> </p> 24 25 </div> 26 </div> 27 </div> 28 </div> 29 <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script> 30 <script> 31 $(function(){ 32 $(document).on("click",‘#rehindPhone‘,bindInputclick()); 33 }); 34 function bindInputclick(){ 35 var i=2; 36 return function(){ 37 if(i%2==0){ 38 $(this).parent().next().slideDown(); 39 } 40 else{ 41 $(this).parent().next().slideUp(); 42 } 43 i++; 44 } 45 } 46 </script> 47 48 </body> 49 </html>

運行結果:

技術分享圖片

基於閉包實現的顯示與隱藏