我有一个ajax,它调用一个php函数来填充我的表。但是每当我单击表中的Edit
按钮时,模态都不会显示。我尝试使用与我的 php echo 按钮相同的代码在测试按钮上正常调用模态,并且它工作正常。我也尝试用onclick
替换href
,但它仍然不起作用。
有效的测试按钮(与 php echo 按钮的代码相同(:
<button id="" class="modal-trigger waves-effect waves-light btn orange lighten-1" href="#modal1">Edit</button>
模 态:
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Modal Header</h4>
<p>A bunch of text</p>
</div>
<div class="modal-footer">
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
</div>
</div>
.PHP:
while ($row = $stmt->fetch()){
echo '<tr>';
echo '<td>'.$row['taskDate'].'</td>';
echo '<td>'.$row['taskName'].'</td>';
echo '<td>'.$row['taskType'].'</td>';
echo '<td>'.$row['duration'].'</td>';
echo '<td>'.$row['startTime'].'</td>';
echo '<td>'.$row['endTime'].'</td>';
echo '<td> <button id="'.$row['taskId'].'" class="modal-trigger waves-effect waves-light btn orange lighten-1" href="#modal1">Edit</button> </td>';
echo '<td> <button id="'.$row['taskId'].'" class="waves-effect waves-light btn red lighten-1">Delete</button> </td>';
echo '</tr>';
}
我不知道我在这里错过了什么。我认为这是我的 php 代码上的东西,因为测试按钮有效。
感谢任何可以帮助我的人!
好吧,
我刚刚解决了自己的问题。
我使用了 materialize js 的 0.98.0(0.97.0(版本。然后用data-target
代替href
,它神奇地工作了!
旧代码:
'<td> <button id="'.$row['taskId'].'" class="modal-trigger waves-effect waves-light btn orange lighten-1" href="#modal1">Edit</button> </td>';
新代码:
'<td> <button id="'.$row['taskId'].'" class="waves-effect waves-light btn orange lighten-1" data-target="editModal">Edit</button> </td>';