2012-10-04 77 views
-1

爲什麼我的onClick不起作用?javascript 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> 

回答

-1

使用此代碼,希望它會工作

<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick="delete_Affiliate(<?php echo $row['affiliateid'];?>);"></a> 
+0

確定我將檢查等待 – user1718865

+0

它有一個錯誤,語法錯誤,意外「?」 – user1718865

+0

回答更新,現在嘗試 –

3

試試這個:

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

也就是說,你需要從呼應PHP的值。

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); 

} 

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>

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>"; 

?> 
+0

感謝男人它真的workssss感謝很多得到了這段代碼運行正確 – user1718865

+0

歡迎您;) –

+0

嗨加我facebook上http://www.facebook.com/macky.miro – user1718865

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> 
+0

嗨嗨得到錯誤這裏我試過你的代碼解析錯誤:語法錯誤,意外'?'在49行上的C:\ xampp \ htdocs \ ralimo-rates-system \ query \ view_affiliate.php – user1718865

0

你必須添加這樣

您的錨標記之間的PHP代碼和回聲聲明
<a href='#' id='delete' title='Delete' class='icon-2 info-tooltip' onclick='delete_Affiliate("<?php echo $row['affiliateid']; ?>")'></a> 

你沒有添加這個

<?php echo $row['affiliateid']; ?> 

在你的錨標記,所以只需添加它並檢查出來。

我希望它會幫助你

+0

基本上這不是早期答案的說法嗎? – Barmar

0

試試這個

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

嗨,無論如何,我已經明白了 – user1718865