我想隱藏基於按鈕單擊的窗體。下面是我的代碼:在PHP文件中輸入錯誤
<html>
<head>
<title>Programma per connettersi a un database tramite il linguaggio PHP
</title>
<style>
#mybutton {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: orange;
margin-top: 20px;
}
</style>
</head>
<body>
<button onclick="button()">Inserisci studente</button>
<div id="mybutton">
<div>
<input type="hidden" name="action" value="submit"> Nome Studente:<br>
<input name="Nome" type="text" value="" placeholder="Inserisci il
nome dello studente" size="30" /><br> Cognome Studente:<br>
<input name="Cognome" type="text" value="" placeholder="Inserisci
il cognome dello studente" size="30" /><br> Eta Studente:<br>
<input name="Eta" type="integer" value="" placeholder="Inserisci
l'età dello studente" size="30" /><br>
<input type="submit" name="insert" value="Inserisci" />
</div>
</div>
<br><br><br>
<button onclick="button()">Aggiorna nome</button>
<div id="mybutton">
Inserisci il nome dello studente da modificare nello spazio sottostante
<br>
<div>
<input type="hidden" name="action" value="submit"> Nuovo Nome:<br>
<input name="NewName" type="text" value="" placeholder="Inserisci il
nuovo nome" size="30" /><br> Vecchio Nome:<br>
<input name="OldName" type="text" value="" placeholder="Inserisci il
nome attuale" size="30" /><br>
<input type="submit" name="insert" value="Aggiornare" />
</div>
</div>
<script>
function button() {
var x = document.getElementById('mybutton');
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
</script>
</body>
</html>
當點擊第一個按鈕,一切正常,但是在第二種情況下,當我按下按鈕「Aggiorna諾姆」,形式不隱藏。 爲什麼第一個按鈕工作,第二個按鈕不工作?
不能有多個具有相同ID的元素。 ID對於整個文檔必須是唯一的。如果_do_具有多個具有相同ID的元素,它將始終使用第一個元素。 –
您還需要關閉表單。你打開兩個,但你沒有關閉任何。 –
@SvenTheSurfer - 當你建議編輯時,不要改變原始代碼_。例如,您的編輯完全刪除了表單元素。 –