您好我暂时停留在此错误上,似乎无法找到问题所在的位置...... 我基本上动态地使用php:
为我的数据库中的每一行创建带有按钮的多个列表项<div id="upgrades">
<ul>
<?php
for($i=0;$i<count($_SESSION['upgrades']);$i++)
{
$class = '';
if($_SESSION['upgrades'][$i]['gekocht'] == TRUE)
{
$class = 'gekocht';
}
echo '
<li>
<button class="upgradebutton'.$class.'" data-id="'.$_SESSION['upgrades'][$i]['update_id'].'">'.$_SESSION['upgrades'][$i]['naam'].'</button>
</li>';
}
?>
</ul>
</div>
然后在点击每个按钮时使用javascript点击升级时,检查是否有我附加的类:
$(document).ready(function(){
$('.upgradebutton').click(function(){
if(!$(this).hassClass('upgradebuttongekocht'))
{
var upgrade_id = $(this).attr("data-id");
alert(upgrade_id);
$(this).addClass('gekocht');
window.upgrades[upgrade_id][gekocht] = 1;
}else{
alert("already Bought");
}
});
});