2017-05-24 18 views
-2

我所要求的是非常非常簡單,但即時通訊相當卡住,即時通訊嘗試修改舊的HTML表單並加入一些JavaScript或反應。所有我想在這裏做的是比方說原來的形式(<form>)是我怎樣才能修改我的HTML表單上單擊以啓用更改表單輸入的按鈕

用戶名:
密碼:

,我想添加一個按鈕,點擊它改變了形式

登錄密鑰:

隱藏用戶名和密碼字段。基本上用登錄密鑰表格替換它們。任何答案都非常好。謝謝。

+1

所以,你想要一個JavaScript的解決方案,你目前正在卡住。你特別注意什麼?你有沒有寫過任何JavaScript? –

回答

0

我不知道了很多關於JavaScript的,但也許你可以使用PHP來做到這一點寫東西像

<?php 
    if (isset($_POST['buttonNewForm'])) 
    { 
     echo "......your new form......."; 
     echo "<form action=page.php method=post> 
      <button name='buttonOldForm'>Button</button> 
     </form>" 
    } 
    else 
    { 
     echo "......your old form......."; 
     echo "<form action=page.php method=post> 
      <button name='buttonNewForm'>Button</button> 
     </form>" 
    } 
?> 

文件必須是page.php文件

我沒有檢查代碼,但它應該按照您希望在第一次顯示舊窗體時的方式工作。

0

你可以使用jQuery隱藏和顯示來完成你想要的東西。

$("#thisIsYourBtnID").click(function() { 
    $("#div").hide(); //this is your div that has username and password inputs in it 
    $("#div2").show(); //this is your new div showing login key form 
}); 
-1

我做了一個非常簡單的javascript函數,是什麼你想幹什麼?

<html> 
 

 
<body> 
 

 
    <form> 
 
     <div id="divNo1"> 
 
      <label>Username : </label> 
 
      <input type="text" /> 
 
      <br /> 
 
      <label>Password : </label> 
 
      <input type="text" /> 
 
     </div> 
 

 
     <div id="divNo2" style="display:none"> 
 
      <label>Login Key : </label> 
 
      <input type="text" /> 
 
     </div> 
 
    </form> 
 
    <button onclick="changeDisplay()">Button</button> 
 
</body> 
 

 
<script type="text/javascript"> 
 
    function changeDisplay() { 
 
     var div1 = document.getElementById("divNo1"); 
 
     var div2 = document.getElementById("divNo2"); 
 
     if (div1.style.display == 'none') { 
 
      div1.style.display = ''; 
 
      div2.style.display = 'none'; 
 
     } else { 
 
      div1.style.display = 'none'; 
 
      div2.style.display = ''; 
 
     } 
 
    } 
 

 
</script> 
 

 
</html>

相關問題