我使用php动态生成一些按钮:
<?php
while( $row = mysql_fetch_assoc( $result ) ){
echo "<tr>
<td><a href='updateproject.php?id=$row[ID]' class='btn btn-warning btn-mini'>
<i class='icon-white icon-pencil'></i>
</a>
<a href='deleterow.php?del=$row[ID]' onclick='return confirm('You want to delete this?');' class='btn btn-danger btn-mini'>
<i class='icon-white icon-remove'></i>
</a>
</td>
<td>{$row['Projectname']}</td>
<td>{$row['Personincharge']}</td>
<td>{$row['Description']}</td>
<td>{$row['CreationDate']}</td>
<td>{$row['Location']}</td>
</tr>\n";
}
?>
我尝试了很多东西,但它没有用。没有警报即将到来。它刚被删除......
答案 0 :(得分:2)
你的斜线将会破裂,因为它会认为声明在confirm('
结束。试试这个:
onclick=\"return confirm('You want to delete this?');\"
答案 1 :(得分:0)
我会将表封装在表单中并使用以下代码。
<form onsubmit=" return window.confirm('Are you sure?');">
<?php
//Add button php here and fields
?>
</form>
答案 2 :(得分:0)
<script src="jquery.js"></script>
<script>
$(document).ready(function() {
$('.delete').click(function(event){
event.preventDefault();
confirm('You want to delete this?');
});
});
//db connection goes here
$query = mysql_query("Select * FROM `table_name`");
echo "<table>";
while( $row = mysql_fetch_assoc( $query ) ){
echo
"<tr>
<td> <a href='deleterow.php?del={$row['id']}' class='delete'>Delete</a>
</td>
<td>{$row['Projectname']}</td>
<td>{$row['Personincharge']}</td>
<td>{$row['Description']}</td>
<td>{$row['CreationDate']}</td>
<td>{$row['Location']}</td>
</tr>\n";
}
echo "</table>";