-1

为什么我的 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>
4

8 回答 8

3

尝试这个:

delete_Affiliate(" <?php echo $row['affiliateid']; ?>")

也就是说,您需要从 PHP 中回显该值。

于 2012-10-04T08:46:32.273 回答
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);

}

于 2012-10-04T08:47:22.483 回答
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>

于 2012-10-04T08:47:28.347 回答
0

尝试这个

delete_Affiliate(<?php echo $row['affiliateid']; ?>);
于 2012-10-04T11:05:15.457 回答
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>";

?>
于 2012-10-04T08:48:42.670 回答
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>
于 2012-10-04T08:49:14.267 回答
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']; ?> 

在你的锚标签中,所以只需添加它并检查它。

我希望它会帮助你

于 2012-10-04T09:48:41.780 回答
-1

使用此代码,希望它会工作

<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick="delete_Affiliate(<?php echo $row['affiliateid'];?>);"></a>
于 2012-10-04T08:46:31.657 回答