我在使用 Bootstrap 的模式对话框时遇到问题。 这是我的代码:我想正确显示 id 按钮,而不仅仅是打开模式对话框,但它不起作用。它始终显示空白。 但是,如果我将类型“按钮”更改为“提交”,则会获得正确的 ID,但不显示模式对话框。有什么问题??感谢您的关注。这是我的代码:
<table class="table table-bordered">
<tr>
<td> <input type="checkbox" id="box1" name="box1"> <b>Seleziona tutto</b></td>
<td> <b>Pratica</b> </td>
<td> <b>Filiale</b> </td>
</tr>
<?php
$query = mysql_query("SELECT * from plprat ") ;
while ($row = mysql_fetch_array($query)) {
echo "<tr>";
echo "<td><input type='checkbox' class='box' name='box[]' value=".$row['id']."></td>";
echo "<td>" . $row['pratica'] . "</td>";
echo "<td>" . $row['filiale'] . "</td>";
//echo "<td><form method='POST' action='Cancella.php'><button type='submit' name='Cancella' class='btn btn-default' value=".$row['id'].">Cancella</button></form></td>";
echo "<td><form method='GET'><button type='button' id='modifica' name='modifica' data-toggle='modal' data-target='#myModal' class='btn btn-default' value=".$row['id'].">Modifica</button></form></td>";
echo "</tr>";
}
?>
</table>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modifica dati</h4>
</div>
<div class="modal-body">
<?php
$id = $_GET['modifica'];
echo $id;
$query = mysql_query("SELECT * FROM plprat WHERE id = $id");
while ($row = mysql_fetch_array($query)) {
?>
<b>Pratica</b> <input type="text" id="pratica" name="pratica" value="<?php echo $row['pratica']; ?>">
<b>Filiale</b> <input type="text" id="filiale" name="filiale" value="<?php echo $row['filiale']; ?>">
<?php
}
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Chiudi</button>
<button type="submit" id="salva" name="salva" class="btn btn-primary">Modifica</button>
</div>
</div>
</div>
</div>
最佳答案
这种行为是您编码的,让我解释一下发生了什么。
为什么这不起作用?
您将模态按钮放入表单中,但不在模态中使用表单。
因此,如果您将模态按钮更改为提交,当您单击它时它会提交它,但您的模态未打开,甚至...页面已经提交了表单。
您的模态不包含任何 <form>
,因此您的“保存”按钮不在 <form>
中并且永远不会提交任何东西。
如何解决这个问题?
首先删除包裹模态按钮的表单标签,它没有用。 直接将表单标签作为 .modal-content 的子标签,并将所需的输入数据放入其中。
我能为您提供更多帮助吗?
- 在 PHP 中,仅使用一个 echo 来显示多行,您正在制作 无缘无故地使用太多 echo 会导致速度变慢。
- 更喜欢用英语编写代码,避免使用自己的语言(如果不是英语),这样可以让其他人更容易理解它,也可以让它更有值(value)。
- 动态填充模态框。
- 您可能需要这个:JSON data into a Bootstrap modal
- 为您的 DBMS 使用 PHP 框架或至少一个库。
关于javascript - 提交时的 Bootstrap 模态对话框不显示 id 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36247131/