我正在尝试生成一组N个按钮,一个用于数据库表的每一行,我需要通过将<div>
设置为style="display:none"
来显示style="display:block"
单击按钮,此<div>
将显示一个表单。
到现在为止我得到了这个:
home.PHP
<div id="add" style="display:none;">
<form action="#" method="post" id="form">
<div src="close" id="close" onClick="div_hide()">X</div>
Aggiungi
<input type="text" name="soldi" id="campo" placeholder="Soldi">
<a id="submit" href="">
<button>Aggiungi</button>
</a>
</form>
</div>
<?php
while($sezioni = mysqli_fetch_assoc($sezione_sql)){
echo "<div class =\"sezione\">
<a id=\"popup\" onclick=\"div_show()\">
<div class=\"pulsante\">add</div>
</a>
</div>";
}
?>
java.JS
function div_show() {
document.getElementById('add').style.display = "block";
}
function div_hide(){
document.getElementById('add').style.display = "none";
}
如何在提交时调用一个函数来更新确定的数据库行,输入一个按下的按钮的ID?
答案 0 :(得分:1)
传递db_id:
while($sezioni = mysqli_fetch_assoc($sezione_sql)){
$db_id = $sezioni['id']; // id from database
echo "<div class =\"sezione\">
<a id=\"popup\" onclick=\"div_show($db_id )\">
<div class=\"pulsante\">add</div>
</a>
</div>";
}
在表单中添加隐藏的输入字段
<input type="hidden" name="db_id" id="db_id" value="">
在Javascript函数中
function div_show(db_id) {
document.getElementById('add').style.display = "block";
document.getElementById('db_id').value = db_id;
}