简体   繁体   English

使用 jQuery 更改特定 Div 标签内的 TD 值

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

I have the following HTML Table,我有以下 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>

When i click on the button with id Discount, I need to change the value to the TD inside the div Tag with id "total" and set its value to another JavaScript variable?I tried the following, but it's not working.当我单击带有 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");


}); 

Try with my code that help you尝试使用我的代码来帮助您

change HTML <div id="totalone">$875.00</div> to $<span id="totalone">875.00</span>将 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