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'); –
* mysql_fetch_assoc *の代わりに* mysqli_fetch_assos *を使用することが推奨されています。 –
'$(this).attr( 'data-productname')' – Beginner