[英]Using Dalekjs test tool, how to select Option in Dropdown(Select element) when there is no “value” attribute in Option tag?
[英]How can i get multiple value using dropdown select option data attribute?
我想使用數據屬性獲取兩個數據,並在兩個單獨的輸入字段中以只讀方式顯示這兩個值。
我可以正確地獲得一個值。 數據價格,但我無法獲得數據銷售。
$('.selectProduct').on('change', function() { $('.regularPrice').val( $(this).find(':selected').data('price') ); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select id="selectProduct" class="form-control selectProduct" name="productId"> <option selected="">Select Product</option> <option data-price="150" data-salep="50" value="1">Product 1</option> <option data-price="120" data-salep="110" value="2">Product 2</option> </select> <div class="row"> <div class="col-md-6"> <div class="form-group form-group-sm"> <label>Regular Price</label> <input type="text" readonly="" class="form-control regularPrice" id="regularPrice" name="regularPrice" value=""> </div> </div> <div class="col-md-6"> <div class="form-group form-group-sm"> <label>Sale Price</label> <input type="text" readonly="" class="form-control salePrice" id="salePrice" name="salePrice" value=""> </div> </div> </div>
很簡單,使用與salep
相同的代碼,例如:
$('.selectProduct').on('change', function() { $('.regularPrice').val( $(this).find(':selected').data('price') ); $('.salePrice').val( $(this).find(':selected').data('salep') ); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select id="selectProduct" class="form-control selectProduct" name="productId"> <option selected="">Select Product</option> <option data-price="150" data-salep="50" value="1">Product 1</option> <option data-price="120" data-salep="110" value="2">Product 2</option> </select> <div class="row"> <div class="col-md-6"> <div class="form-group form-group-sm"> <label>Regular Price</label> <input type="text" readonly="" class="form-control regularPrice" id="regularPrice" name="regularPrice" value=""> </div> </div> <div class="col-md-6"> <div class="form-group form-group-sm"> <label>Sale Price</label> <input type="text" readonly="" class="form-control salePrice" id="salePrice" name="salePrice" value=""> </div> </div> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.