<?php foreach($platforms as $platform): ?>
<input type='button' value='Select' class="button" id="button_<?php echo $platform->id ?>" />
<?php endforeach; ?>
<script>
$("#button_<?php echo $platform->id ?>").click(function(){
alert('something');
});
</script>
我没有得到我的榜样。有没有办法在jQuery选择器中嵌入codeigniter代码?如果是这样的话?
答案 0 :(得分:1)
要使用$platform->id
,您需要将其移到这样的foreach中:
<?php foreach($platforms as $platform): ?>
<input type='button' value='Select' class="button" id="button_<?php echo $platform->id;?>" />
<script>
$("#button_<?php echo $platform->id ?>").click(function(){
alert('something');
});
</script>
<?php endforeach; ?>
因为$platform
仅在foreach中声明,但您尝试在外部访问它。