Javascript 引导引导框在消息中显示变量

Javascript 引导引导框在消息中显示变量,javascript,php,jquery,twitter-bootstrap,bootbox,Javascript,Php,Jquery,Twitter Bootstrap,Bootbox,我想让对话框中的消息显示类似“选择您想要踢/禁止的方式(玩家名称)” 我当前的代码如下所示 $(document).on("click", ".btn-ban", function(e) { var username = ($(this).attr('id')); bootbox.dialog({ message: "Choose how you want to ban "+$username, title: "Ban Player",

我想让对话框中的消息显示类似“选择您想要踢/禁止的方式(玩家名称)”

我当前的代码如下所示

$(document).on("click", ".btn-ban", function(e) {
    var username = ($(this).attr('id'));
    bootbox.dialog({
       message: "Choose how you want to ban "+$username,
       title: "Ban Player",
       backdrop:false,
       buttons: {
我觉得剩下的代码并不重要

我试着从ancor标记中获取id,php将其定义为播放器名称

但是自从我在消息中添加了“+$uername”之后,对话框就不会显示了


有什么想法吗?

它的
username
不是
$username
之类的

message: "Choose how you want to ban "+username,
完整代码

$(document).on("click", ".btn-ban", function(e) {
    var username = this.id; // you can use it simply without using attr()
    bootbox.dialog({
       message: "Choose how you want to ban "+username,
       title: "Ban Player",
       backdrop:false,
       buttons: {

如果您想连接
php
varialbe,那么以这种方式使用

$(document).on("click", ".btn-ban", function(e) {
var username = this.id; // you can use it simply without using attr()
bootbox.dialog({
   message: "Choose how you want to ban "+ <?php echo $username; ?>,
   title: "Ban Player",
   backdrop:false,
   buttons: {
$(文档)。在(“单击”上,“.btn禁止”,功能(e){
var username=this.id;//不用attr()就可以简单地使用它
bootbox.dialog({
消息:“选择要禁止的方式”+,
标题:“禁止玩家”,
背景:错,
按钮:{

只需使用username,因为它的变量需要jsfiddle中的完整代码,或者如果您想使用php变量,则将其放入php标记中。除了一件非常重要的事情,this.id不会返回任何内容。如果
元素
具有
id属性,它将
返回id