javascript 如何访问输入标记值

pftdvrlh  于 2023-04-28  发布在  Java
关注(0)|答案(1)|浏览(119)

bounty还有5天到期。回答此问题可获得+50声望奖励。Hem正在寻找典型答案

更新:我通过创建一个新变量并使用它并将该变量分配给finalPrice来解决这个问题,因为我认为可以通过不同的方式来解决这个问题,我想访问这里定义的值finalPrice,就在add_to_download_entries函数上面:

var counts = 1;
 var checkboxes;
 var finalPrice;

上面的finalPrice我想访问并将该值赋给payModal函数内部的finalPrice = 4444,它应该是来自add_to_download_entries函数上面定义的finalPrice变量的finalPrice的值。所以当我在文档中执行finalPrice = "Pay Now $" + Number(counts) * Number(22);时。ready函数我想把这个finalPrice的值赋给finalPrice = 44;在这里的PayModal()函数中,而不是44,我该怎么做呢?

<script>   
 // Pay Modal 
    async function payModal() {
      
      await fetch("{{ route('paymentModal') }}")
      .then(response => response.json())
        .then(response => {
          const form = document.getElementById('payment-form');
          _key_for_ss = response.paymentIntent.client_secret;
          paymentIntentID = response.paymentIntent.id;
          finalPrice = 44; 
          async function openModal() {
            await createCard();
            $('#pay-modal').modal('show');
          }
          openModal();
        })
    }
    
    var selected_lostwill_array = [];
    
     var counts = 1;
     var checkboxes;
     var finalPrice;
    function add_to_download_entries(data) {
       checkboxes = document.querySelectorAll('input[name="checkWills"]:checked');
        counts = checkboxes.length;
      if($.inArray(data, selected_lostwill_array) >= 0){
        selected_lostwill_array = $.grep(selected_lostwill_array, function(value){
             return value != data;
           });
         }else{
          selected_lostwill_array.push(data);
         }
         // DataTables Functions 
    $(document).ready( function () {
        $('#org_lost_table').DataTable();
        $('#all_lost_table').DataTable();
        if(counts>0){
             finalPrice = "Pay Now $" + Number(counts) * Number(22);
            
            $( "#payment-sub-btn" ).text(finalPrice);
           }else $( "#payment-sub-btn" ).text(0); 
    } );
    }
</script>
k4emjkb1

k4emjkb11#

我通过创建一个名为finalPrices的新变量并将finalPrices的值赋给finalPrices = Number(counts) * Number(22);来解决这个问题,因此现在它不会获得文本,而只是一个整数值

var finalPrices;
    async function payModal() {
      
      await fetch("{{ route('paymentModal') }}")
      .then(response => response.json())
        .then(response => {
          const form = document.getElementById('payment-form');
          _key_for_ss = response.paymentIntent.client_secret;
          paymentIntentID = response.paymentIntent.id;
          finalPrice = finalPrices; 
          async function openModal() {
            await createCard();
            $('#pay-modal').modal('show');
          }
          openModal();
        })
    }

function add_to_download_entries(data) {
   checkboxes = document.querySelectorAll('input[name="checkWills"]:checked');
    counts = checkboxes.length;
  if($.inArray(data, selected_lostwill_array) >= 0){
    selected_lostwill_array = $.grep(selected_lostwill_array, function(value){
         return value != data;
       });
     }else{
      selected_lostwill_array.push(data);
     }
     // DataTables Functions 
$(document).ready( function () {
    $('#org_lost_table').DataTable();
    $('#all_lost_table').DataTable();
    if(counts>0){
       finalPrices = Number(counts) * Number(22);
         finalPrice = "Pay Now $" + Number(counts) * Number(22);
        
        $( "#payment-sub-btn" ).text(finalPrice);
       }else $( "#payment-sub-btn" ).text(0); 
} );
}

相关问题