如何在确认文本中使用jquery变量值

时间:2017-04-13 07:12:46

标签: javascript jquery html ajax

好的,所以我想在我的警告框中获取jQuery变量值。我尝试了一些东西,但这并没有像我预期的那样给我结果。

$(document).ready(function() {
  $("#submit").click(function() {
        var dataString = {
            amount: $("#amount").val()
        };
        var getamt = dataString.amount;
    $.confirm({
        title: 'Confirm!',
        content: 'Are you sure you want to transfer $"'.getamt.'" to wallet?', // not getting the result
        buttons: {
        confirm: function () {
                    $.ajax({
                        type: "POST",
                        dataType : "json",
                        url: "add-funds-process.php",
                        data: dataString,
                        cache: true,
                  beforeSend: function(){
                            $("#submit").hide();
                            $("#loading-rent").show();
                            $(".message").hide();
                  },
                        success: function(json){
                            setTimeout(function(){
                                $(".message").html(json.status).fadeIn();
                                $('#wallet').html('$' + json.wallet);
                                $('#balance').html('$' + json.balance);
                                $("#submit").show();
                                $("#loading-rent").hide();
                            },1000);
                        }
                    });
        },
        cancel: function () {
          $.alert('<span style="font-size: 23px">Upgrade Cancelled!</span>');
        }
        }
        });
        return false;
    });
});

你们这些专家可以帮助我吗?我会很感激的。

1 个答案:

答案 0 :(得分:0)

您正在使用php操作符.和javascript。在javascript +中用于将变量与字符串进行联接。

运行此示例可能对您有帮助....

&#13;
&#13;
$("#submit").click(function() {
    $.confirm({
        title: 'Confirm!',
        content: 'Are you sure you want to transfer "' + $("#amount").val()  + '" to wallet?', // not getting the result
        buttons: {
        confirm: function () {
          $.alert('confirm');
        },
        cancel: function () {
          $.alert('<span style="font-size: 23px">Upgrade Cancelled!</span>');
        }
        }
        });
        return false;
    });
&#13;
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.0/jquery-confirm.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.2.0/jquery-confirm.min.js"></script>

<button id="submit">Hello</button>
<input type="text" id="amount" placeholder="Enter the amount">
&#13;
&#13;
&#13;