在html中显示选择选项的值

布鲁诺

我有一个清单 标签,则可通过在线电子表格获取商品价值。选择一个选项时,该值不会实时显示在html中。有谁能够帮我?我正在尝试解决它,但找不到错误。

CODEPEN链接示例

 $(document).ready(function() {
       var sheetURL =
         "https://spreadsheets.google.com/feeds/list/1J0qyxUCCkvcFGZ6EIy9nDOgEuTlpI5ICVG3ZsBd_H-I/1/public/values?alt=json";
       $.getJSON(sheetURL, function(data) {
         var entryData = data.feed.entry;
         console.log(data);
         jQuery.each(entryData, function() {
           $("#divTax").append(
      
      '<option  hidden="hidden" selected="selected"  value="0">CHOISE</option><option value="' + this.gsx$values.$t +  '">' + this.gsx$names.$t + '&nbsp;&nbsp;&nbsp;$' + this.gsx$values.$t + '</option>'
     
           );
         });
       });
      });

  
var totalWithTax = $('#divTax :selected').val();
  $('.total').html(totalWithTax);                         
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

 <select style="width: 80%;" id="divTax"></select>
  <br>  
Total:<div class="total"></div>

巴尔玛

您可以将显示选择的代码放在事件侦听器中。

$(document).ready(function() {
  var sheetURL =
    "https://spreadsheets.google.com/feeds/list/1J0qyxUCCkvcFGZ6EIy9nDOgEuTlpI5ICVG3ZsBd_H-I/1/public/values?alt=json";
  $.getJSON(sheetURL, function(data) {
    var entryData = data.feed.entry;
    jQuery.each(entryData, function() {
      $("#divTax").append(

        '<option  hidden="hidden" selected="selected"  value="0">CHOISE</option><option value="' + this.gsx$values.$t + '">' + this.gsx$names.$t + '&nbsp;&nbsp;&nbsp;$' + this.gsx$values.$t + '</option>'

      );
    });
  });
  
  $("#divTax").change(function() {
    var totalWithTax = $(this).val();
    $('.total').text(totalWithTax);
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<select style="width: 80%;" id="divTax"></select>
<br> Total:
<div class="total"></div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章