簡體   English   中英

使用 jQuery 更改特定 Div 標簽內的 TD 值

[英]Change the TD value inside a particular Div Tag inside using jQuery

我有以下 HTML 表,

<table id="items">
   <tr class="total_up">

          <td colspan="2" class="blank"> </td>
          <td colspan="2" class="total-line">Total</td>

        <td class="total-value" id="total"><div id="totalone">$875.00</div></td> 
      </tr>

       <tr class="disc" id="disc">

          <td colspan="2" class="blank"> </td>
          <td colspan="2" class="total-line">Discount</td>
          <td class="total-value" id="discount"><div id="discountid"><input type="text" name="disco" class="dis"/></div> </td>
      </tr>



      <tr class="tax_up">
          <td colspan="2" class="blank"> </td>
          <td colspan="2" class="total-line balance">tax</td>
          <td class="total-value" id="tax"><div id="tax">00</div></td>
      </tr>

</table>

當我單擊帶有 id Discount 的按鈕時,我需要將 id 為“total”的 div 標簽內的值更改為 TD,並將其值設置為另一個 JavaScript 變量?我嘗試了以下操作,但它不起作用。

 $(".discountbtn").click(function(){

var test=$("#items #disc .dis").val(); //Easiest method


    console.log("lol");
    console.log(test);
    var tot = roundNumber(test,2);

    var new_tot=window.finale-tot;
    console.log(window.finale);

    console.log(new_tot);

    $('#items #totalone').html("$"+new_tot);

   //alert("button");


}); 

嘗試使用我的代碼來幫助您

將 HTML <div id="totalone">$875.00</div>更改$<span id="totalone">875.00</span>

$(document).ready(function() {
    $("#discountbtn").click(function(){
        var test=$("#items #disc .dis").val(); 
        console.log(test);

        var oldTotal = $("#totalone").text();
        console.log(oldTotal);

        var tot = Math.round(test * 100) / 100;
        var new_tot=parseFloat(oldTotal)-tot;
        console.log(new_tot);

        $('#items #total').html(new_tot); //It was a jQuery selector glitch.
    }); 
});
$('#items #totalone').html("$"+new_tot);

暫無
暫無

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

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