我試圖確保用戶想要從數據庫中刪除條目。我寧願停止初始函數中的動作,也不願意在刪除函數中執行它,因爲這樣做更有意義。無論如何,網站會不斷跳過確認對話框,然後繼續刪除條目。我不確定它是否只是一個語法錯誤,但我不明白爲什麼我的jQuery沒有跳閘。jQuery確認鏈接點擊
<script type="text/javascript" src="jquery-1.10.2.min.js" ></script>
<script>
$(document).ready(function(){
('a.confirm').click(function(event){
event.preventDefault();
var url = $(this).attr('href') ;
var confirm_box = confirm("Are you sure you want to delete this player?");
if(confirm_box){
window.location = url;
}
});
});
</script>
<?php
function roster_table()
{
try{
if(isset($_SESSION['session_id']) )
{
$db = honneyconnect() ; // db connection established
if(mysqli_connect_error())
{
throw new Exception("Could not connect to the database") ;
}
$query = 'select * from roster' ;
$players = $db->query($query) ;
if(!$players )
{
throw new Exception ("Query returned zero results") ;
}
else
{
$number_of_players = $players->num_rows ;
echo "<div id='player_table'>
<table><th>Hells Canyon Honeys Active Skaters</th>" ;
for($i = 0; $i < $number_of_players; $i++)
{
$row = $players->fetch_row() ;
echo "<tr><td>".$row[0]."</td><td>".$row[1]."</td><td>".$row[2]."</td>
<td><a href='http://localhost/honeysproject/editplayer.php?player_id=".$row[0]."'>Edit</a></td>
<td><a class='confirm' href='http://localhost/honeysproject/deleteplayer.php?player_id=".$row[0]."'>Delete</a></td></tr>" ;
}
echo "<tr><td><a href='http://localhost/honeysproject/playerinfoentry.php'>Add Player</a></td></tr></table></div>" ;
}
}
else
{
throw new Exception("You are no longer authorized to view this document. Please re-authenticate!<br>") ;
session_destroy() ;
}
}
catch(Exception $error)
{
echo $error ;
}
}
應該'('a.confirm')。'不是'$('a.confirm')。'?而你缺少''}}'for your document.ready – putvande
PHP在這裏是無關緊要的。改爲發佈您的呈現HTML。 – j08691