我想隐藏基于按钮单击的窗体。下面是我的代码:在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 - 当你建议编辑时,不要改变原始代码_。例如,您的编辑完全删除了表单元素。 –