2
下面是我的PHP代碼。我顯示3張圖片,如果我點擊任何圖片或產品,我需要在彈出窗口中添加該產品。我試圖獲得產品名稱,但我不能。如何解決這個問題。無法獲取href使用jQuery的屬性
<?php
$i = 0;
while ($row = mysql_fetch_assoc($result))
{
echo"<td style='background-color:#FFFFFF;' height='383'>
<a href='#myModal?productname={$row["productname"]} 'id='burl' role='button' data-productname='{$row["productname"]}' data-toggle='modal' data-target='#myModal'>
<img src='images/{$row["productname"]}.jpg' width='255'/>
</a>
</td>";
}
mysql_free_result($result);
?>
JQuery的值編碼:
$(document).ready(function() {
$('#myModal').on('shown.bs.modal', function() {
console.log($(this).data('productname'));
})
})
通常只是$(選擇).attr( 'href' 屬性); –
請勿使用* mysqli_fetch_assos *而不使用* mysql_fetch_assoc * –
'$(this).attr('data-productname')' – Beginner