1

I am having difficulty creating drop down menu's that when selected multiply for total. 由于某种原因,总数没有出现?这是我到目前为止所拥有的:

<div id="cid_7" class="form-input">
      <select class="form-dropdown validate[required]" class="DropChange" style="width:150px" id="input_7" name="q7_ticketOptions">
        <option>  </option>
        <option value="300"> VIP Floor Seats - $300.00 </option>
        <option value="40"> Section 101 Upper Level - $40.00 </option>
        <option value="60"> Section 101 Mid Level - $60.00 </option>
        <option value="150"> Section 101 Lower Level - $150.00 </option>
        <option value="40"> Section 102 Upper Level - $40.00 </option>
        <option value="60"> Section 102 Mid Level - $60.00 </option>
        <option value="150"> Section 102 Lower Level - $150.00 </option>
        <option value="40"> Section 103 Upper Level - $40.00 </option>
        <option value="60"> Section 103 Mid Level - $60.00 </option>
        <option value="150"> Section 103 Lower Level - $150.00 </option>
        <option value="20"> Section 104 Upper Level - $20.00 </option>
        <option value="60"> Section 104 Mid Level - $60.00 </option>
        <option value="20"> Section 107 Upper Level - $20.00 </option>
        <option value="60"> Section 107 Mid Level - $60.00 </option>
        <option value="40"> Section 108 Upper Level - $40.00 </option>
        <option value="60"> Section 108 Mid Level - $60.00 </option>
        <option value="150"> Section 108 Lower Level - $150.00 </option>
        <option value="40"> Section 109 Upper Level - $40.00 </option>
        <option value="60"> Section 109 Mid Level - $60.00 </option>
        <option value="150"> Section 109 Lower Level - $150.00 </option>
        <option value="40"> Section 110 Upper Level - $40.00 </option>
        <option value="60"> Section 110 Mid Level - $60.00 </option>
        <option value="150"> Section 110 Lower Level - $150.00 </option>
        <option value="40"> Section 111 Upper Level - $40.00 </option>
        <option value="60"> Section 111 Mid Level - $60.00 </option>
        <option value="150"> Section 111 Lower Level - $150.00 </option>
        <option value="40"> Section 112 Upper Level - $40.00 </option>
        <option value="60"> Section 112 Mid Level - $60.00 </option>
        <option value="150"> Section 112 Lower Level - $150.00 </option>
        <option value="20"> Section 113 Upper Level - $20.00 </option>
        <option value="60"> Section 113 Mid Level - $60.00 </option>
        <option value="40"> Section 114 Upper Level - $40.00 </option>
        <option value="60"> Section 114 Mid Level - $60.00 </option>
        <option value="40"> Section 115 Upper Level - $40.00 </option>
        <option value="60"> Section 115 Mid Level - $60.00 </option>
        <option value="20"> Section 116 Upper Level - $20.00 </option>
        <option value="60"> Section 116 Mid Level - $60.00 </option>
        <option value="40"> Section 117 Upper Level - $40.00 </option>
        <option value="60"> Section 117 Mid Level - $60.00 </option>
        <option value="150"> Section 117 Lower Level - $150.00 </option>
        <option value="40"> Section 118 Upper Level - $40.00 </option>
        <option value="60"> Section 118 Mid Level - $60.00 </option>
        <option value="150"> Section 118 Lower Level - $150.00 </option>
      </select>
    </div>
  </li>
  <li class="form-line" id="id_23">
    <label class="form-label-left" id="label_23" for="input_23"> Quantity<span class="form-required">*</span></label>
    <div id="cid_23" class="form-input">
      <select class="form-dropdown validate[required]" class="DropChange" style="width:150px" id="input_23" name="q23_quantity">
        <option>  </option>
        <option value="1"> 1 </option>
        <option value="2"> 2 </option>
        <option value="3"> 3 </option>
        <option value="4"> 4 </option>
        <option value="5"> 5 </option>
        <option value="6"> 6 </option>
        <option value="7"> 7 </option>
        <option value="8"> 8 </option>
        <option value="9"> 9 </option>
        <option value="10"> 10 </option>
      </select>
    </div>
  </li>
  <li class="form-line" id="id_22">
    <label class="form-label-right" id="label_22" for="total">Total      $</label>
    <div id="cid_22" class="form-input">
      <span id="total" name="q22_total"></span>
    </div>
  </li>

并且使用的jquery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript">
$(function() {
   $(".DropChange").change(function(){
     var  valone = $('#input_7').val();
     var  valtwo = $('#input_23').val();
     var total = ((valone * 1) * (valtwo * 1));
   $('#total').text(total);
  });
 });
</script>

jsfiddle 示例

4

2 回答 2

1

在对文本值执行数学运算之前,您需要将文本值解析为整数(或浮点)值。

var valone = parseInt($('#input_7').val(), 10);
var valtwo = parseInt($('#input_23').val(), 10);
var total = valone * valtwo;
$('#total').text(total);
于 2013-01-22T03:06:01.263 回答
0

只需更改此行并添加 onchange="opConfig.reloadprice () 如下,就可以了。

<select class="form-dropdown validate[required]" class="DropChange" style="width:150px"   id="input_7" name="q7_ticketOptions"onchange="opConfig.reloadPrice ()">
于 2014-01-14T17:08:27.407 回答