在 JS confirm() 方法中使用 PHP 变量
Using a PHP variable into JS confirm() method
这是一个简单的问题,我有一个变量(一个字符串)会根据用户在上一页中的操作而变化,它可以是 'package'、'content' 等
由于修改可能会产生后果,我想通过使用确认方法来确保用户知道他的操作,该方法会说 "are you sure you want to delete this package" 如果这是一个包或 "are you ... this content" 等.
在我的 JS 中,我这样做了:
var sCategorieType = $(this).closest('tr').attr('name');
我想这样做:
var bConfirm = confirm("Are you sure you want to delete this'.sCategorieType.'? ");
这行不通,我想知道为什么并有替代方案。
javascript 中的串联与 PHP 中的不同。在 javascript 中,您可以使用 +
符号连接字符串。
尝试:
var bConfirm = confirm("Are you sure you want to delete this " + sCategorieType + "? ");
用“+”连接,而不是“.”符号,一切都会好起来的! :)
var bConfirm = confirm("Are you sure you want to delete this " + sCategorieType + "? ");
祝你好运!)
这是一个简单的问题,我有一个变量(一个字符串)会根据用户在上一页中的操作而变化,它可以是 'package'、'content' 等
由于修改可能会产生后果,我想通过使用确认方法来确保用户知道他的操作,该方法会说 "are you sure you want to delete this package" 如果这是一个包或 "are you ... this content" 等.
在我的 JS 中,我这样做了:
var sCategorieType = $(this).closest('tr').attr('name');
我想这样做:
var bConfirm = confirm("Are you sure you want to delete this'.sCategorieType.'? ");
这行不通,我想知道为什么并有替代方案。
javascript 中的串联与 PHP 中的不同。在 javascript 中,您可以使用 +
符号连接字符串。
尝试:
var bConfirm = confirm("Are you sure you want to delete this " + sCategorieType + "? ");
用“+”连接,而不是“.”符号,一切都会好起来的! :)
var bConfirm = confirm("Are you sure you want to delete this " + sCategorieType + "? ");
祝你好运!)