2017-04-13 62 views
0

好吧,我想在我的警報框中獲取jQuery變量值。我嘗試了一些東西,但是這並沒有像預期的那樣給出結果。如何在確認文本中使用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; 
    }); 
}); 

你們任何專家都可以幫助我嗎?我會很感激。

+2

使用'+',而不是'.' ...和'VAR getamt = dataString.amt;'會拋出一個錯誤。 –

+0

好像你正在嘗試使用php大聲笑。但是,是的,按照Kartikeya的說法。 –

+0

謝謝..解決了這個問題:) –

回答

0

您正在使用php操作符.使用javascript。在javascript +用於將變量與字符串進行拼接。

運行這個例子,它可以幫助你....

$("#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; 
 
    });
<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">

+0

問題已經解決了上面的意見..謝謝你的時間:) –

+0

好..好。最受歡迎... –

相關問題