簡體   English   中英

Java腳本確認框與PHP

[英]Javascript confirm box with php

我對此主題進行了一些研究,發現在php中使用確認框的一種方法是使用javascript onclick() 我有此代碼不起作用。

 echo '<td class="item_unsold"><a href = "manage-products.php?prod='.$row[0].'"  style="color:red" onclick="return confirm("Are you sure you want to delete this product ?")">Delete</a></td>';

我認為問題出在'"的使用上,但是我不確定如何構造此回顯。當我在單引號中使用confirm('Are you sure you want to delete this product')我也會收到錯誤消息我有什么想法可以構造這種回聲嗎?

您必須轉義單個qoute,這是您的編輯

echo '<td class="item_unsold"><a href = "manage-products.php?prod='.$row[0].'"  style="color:red" onclick="return confirm(\'Are you sure you want to delete this product ?\')">Delete</a></td>';

最小的mod是這樣的:

onclick="return confirm('Are you sure you want to delete this product ?')"

現場示例 | 現場直播

請注意,這是屬性( onclick )上的引號,以及JavaScript代碼上的引號(因為JavaScript支持對字符串使用單引號)。

如果需要在消息中包含撇號(這是很常見的),請記住,屬性的內容是HTML文本,並且在HTML文本中可以使用HTML實體。 所以這也可行:

onclick="return confirm(&quot;You're really sure want to delete this product ?&quot;)"

實時復制 | 實時源 (我更改了消息,因此其中包含一個' 。)

盡管在這種情況下,另一種選擇是使用轉義的撇號:

onclick="return confirm('You\'re really sure want to delete this product ?')"

實時復制 | 現場直播

您只需要小心使用引號即可: PHP String Reference

echo '<td class="item_unsold"><a href = "manage-products.php?prod='.$row[0].'"  style="color:red" onclick="return confirm(\'Are you sure you want to delete this product ?\')">Delete</a></td>';

在這里,我逃避了一組引號,這些引號應該可以為您解決問題。

enter code here echo '<td class="item_unsold"><a href = "manage-products.php?prod='.@$row[0].'"  style="color:red" onclick="return confirm(\'Are you sure you want to delete this product ?\')">Delete</a></td>';

嘗試使用反斜杠轉義單引號

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM