为什么我的onClick不起作用?
当我点击时,我收到如下错误消息:
syntax error : identifier starts immediately after numeric literal
它不会从数据库中确定ID,数据库ID是varchar(50)。
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].")'></a>
<script type="text/javascript">
function delete_Affiliate(id){
alert(id);
}
</script>
答案 0 :(得分:3)
试试这个:
delete_Affiliate(" <?php echo $row['affiliateid']; ?>")
也就是说,您需要回显PHP中的值。
答案 1 :(得分:0)
试试这个
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick="delete_Affiliate(<?php echo $row['affiliateid'] ?>)"></a>
<script type="text/javascript">
function delete_Affiliate(id){
alert(id);
}
答案 2 :(得分:0)
这条线可能有问题
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].")'></a>
它应该是
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid']; ?>")'></a>
答案 3 :(得分:0)
你能发贴你的PHP脚本吗? 你应该有类似的东西:
<?php
echo "<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(\"".$row['affiliateid']."\");return false;'></a>
<script type='text/javascript'>
function delete_Affiliate(id){
alert(id);
}
</script>";
?>
答案 4 :(得分:0)
试试这个:
<?php
echo "<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate(".$row['affiliateid'].");'></a>";
?>
或者这个:
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid'] ?>");'></a>
答案 5 :(得分:0)
你必须像你这样
在你的锚标签之间添加php标签和echo语句<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid']; ?>")'></a>
你没有添加这个
<?php echo $row['affiliateid']; ?>
在你的锚标签中,所以只需添加它并检查出来。
我希望它能帮到你
答案 6 :(得分:0)
试试这个
delete_Affiliate(<?php echo $row['affiliateid']; ?>);
答案 7 :(得分:-1)
使用此代码,希望它能正常工作
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick="delete_Affiliate(<?php echo $row['affiliateid'];?>);"></a>