簡體   English   中英

從javascript中的其他函數獲取值,然后在另一個javascript函數中再次使用它們,並將它們加在一起以查找新結果

[英]Getting Values from other functions in javascript and using them again in another javascript function and add them together to find a new result

<!DOCTYPE html>

<html>

     <head>
          <title>Nitro Motorbike</title>
           <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
          <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
          <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
          <script src="SydCalculation.js"></script>
          <script src="MelCalculation.js"></script>
          <script src="QLDCalculation.js"></script>
          <script src="PerthCalculation.js"></script>
          <script src="TotalSalesCalculation.js"></script>

          <meta name="viewport" content="initial-scale=1, maximum-scale=1">
     </head>

<body>

     <div data-role="page" data-title="Nitro Motorbike">
          <!-- Header-->
          <div data-role="header">
               <h1>Nitro Motorbike Total Sales Calculation Screen of All the Stores</h1>

             <input type="button" value="Home" id="btnAdd" data-inline="true" data-icon="home" data-iconpos="right" 
           onclick="window.location.href='file:///F:/programming%20business%20apps/Assignment/Nitro%20Motorbikemain%20page%20JQuery.html'"> 
           </div>

          <!-- Main-->
          <div data-role="main" class="ui-content">


 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp
 &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp  &nbsp &nbsp


 <img id="Bike"  src="bike8.jpg" height="500" width="1000" align="center" />
               </div>

               <form name ="totalSaleForm" >
                    <div class="ui-field-contain">
                        <label for="txtTotalAmountSyd">Sales by Sydney Store (in $) </label><br>
                        <input type="text" name="txtTotalAmountSyd" id="txtTotalAmountSyd" Disabled> <br>
                        <label for="txtTotalAmountMel"> Sales by Melbourne Store (in $)</label><br>
                        <input type="text" name="txtTotalAmountMel" id="txtTotalAmountMel" Disabled><br>
                        <label for="txtTotalAmountQLD"> Sales by Queensland Store (in $)</label><br>
                        <input type="text" name="txtTotalAmountQLD" id="txtTotalAmountQLD" Disabled ><br>
                        <label for="txtTotalAmountPerth"> Sales by Perth Store (in $)</label><br>
                        <input type="text" name="txtTotalAmountPerth" id="txtTotalAmountPerth" Disabled><br>
                        <label for="txttotalGrossProfit"> Total Gross Profit (in $)</label><br>
                        <input type="text" name="txttotalGrossProfit" id="txttotalGrossProfit" Disabled><br>


            <input type="button" value="Calculate" id="btnAdd" data-inline="true" data-icon="check" data-iconpos="right" 
            onclick="Process()"> <br><br><br><br>

            <input type="button" value="Next"id="btnAdd" data-inline="true" data-icon="carat-r" data-iconpos="right" 
            onclick="window.location.href='file:///F:/programming%20business%20apps/Assignment/TotalNetProfitJquery.html'" /><br> <br>


 </form>
          </div>

          <!-- Footer -->
          <div data-role="footer">
               <h4>Copyright Nitro Motorbike</h4>
          </div>
     </div> 

</body> 
</html>

以下是我用來從以前的javascript文件獲取值的函數,但是我不確定這是否正確。

function addTotalSalesDB() {
     var sql;

     sql = "INSERT INTO Widgets VALUES (";
     sql = sql + totalAmountSyd +", ";
     sql = sql + totalAmountMel + "', ";
     sql = sql + totalAmountQLD + ", ";
     sql = sql + totalAmountPerth + ")";

     db.transaction(function (tx) {
          tx.executeSql(sql);
     });

     PrepareForm();
}

function PrepareForm() {

     totalSaleForm.txtTotalAmountSyd.value = "";
     totalSaleForm.txtTotalAmountMel.value = "";
     totalSaleForm.txtTotalAmountQLD.value = "";
     totalSaleForm.txtTotalAmountPerth.value = "";

     totalSaleForm.txttotalGrossProfit.focus();
}


function Process() {


     totalAmountSyd = totalSaleForm.txtTotalAmountSyd.value;
     totalAmountMel= totalSaleForm.txtTotalAmountMel.value;
     totalAmountQLD =totalSaleForm.txtTotalAmountQLD.value;
     totalAmountPerth = totalSaleForm.txtTotalAmountPerth.value;

     txttotalGrossProfit.value= totalAmountSyd+totalAmountMel+totalAmountQLD+totalAmountPerth;
}

將隱藏字段與要傳遞給另一個函數的值一起使用。 您可以使用jQuery設置和檢索值,即

var field1 = jQuery('#field1').val();

然后用field1做你需要的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM