更改故障单数量时的故障单值乘以

时间:2016-08-04 07:17:15

标签: jquery twitter-bootstrap-3

我写了一个简单的代码来输入门票数量。这是代码:
HTML code:

<div class="col-md-4">
  <div class="panel panel-primary">
    <div class="panel-heading">
      <h3 class="panel-title">Book Now</h3>
    </div>
    <div class="panel-body">
      <div class="form-group">
        <label class="col-md-7 padding_null ticket_qty">Tickets Quantity</label>
        <input class="col-md-5 padding_null text-center" id="demo3" type="text" value="1" name="demo3">
      </div>
      <div class="form-group">
        <div class="row margin_null">
          <label class="col-md-7 padding_null ticket_qty">Total Cost</label>
          <label class="col-md-5 padding_null ticket_qty">$199</label>
        </div>
      </div>
      <div class="form-group">
        <button type="button" class="btn btn-primary center-block proceed_btn">Proceed</button>
      </div>
    </div>
  </div>
</div>

JS code:

$(document).ready(function() {

  $(document).ready(function() {
    $('[data-toggle="tooltip"]').tooltip();
  });

  $("input[name='demo3']").TouchSpin();

});    

JSfiddle链接:https://jsfiddle.net/0b7qf12p/
当我更改票证数量时,应相应更新票价。也就是说,如果我选择机票数量为2,那么机票价格应该变为398.我该怎么办?

2 个答案:

答案 0 :(得分:1)

要实现此目的,您可以挂钩touchSpin插件的 shinyUI(pageWithSidebar( sidebarPanel( selectInput(inputId="Tier", label="Choose Tier:",choices = list("Metro", "Urban", "Semi-Urban","Rural")), selectInput(inputId="Designation", label="Choose Designation:",choices = list("Wealth", "Acquisition", "Service","Others")), "Choose the min & max value-", sliderInput("num1", "No of Sellers:",0,2000,value = c(800,1200),step=1), sliderInput("num3", "Activation Percentage:",0,1,value = c(0.4,0.6),step=0.01), sliderInput("num5", "Case Size:",0,50000,value = c(20000,30000),step=1), sliderInput("num7", "Case Rate:",0,3,value = c(1.2,1.8),step=0.01) ), mainPanel("", h1("Results for Monte Carlo Simulation") )) ) 事件,并更新所需元素的文本(请注意,我在其上放置touchspin.on.startspin以便更轻松地进行选择)。试试这个:

id

Updated fiddle

答案 1 :(得分:0)

这里有一些伪代码可以给你这个想法......

$("#demo3").on("change", function() {
   $("#priceOutput").html($(this).val() * ticketPrice);
});