我想从我的代码中获取所有数据,我只能在 myFunction 上获取一个。如何从 javascript 中的选择选项中获取多个值?我使用 jquery 插件从选择选项中选择多个数据,但是在生成时无法获取所有数据。我希望打印或记录选择框中的所有数据。但如屏幕截图所示,有多个值,但生成时只生成 1 个数据,即 #10Recovery
#select menu
<select id="mySelect2" class="chosen" multiple="true">
{% for product in products.response.result %}
<option value="{{ product.item_name }}">{{ product.item_name }}</option>
{% endfor %}
</select>
#jquery plugin in getting multiple values from a menu
</script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.min.css"
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.min.js"></script>
<script>
jQuery(document).ready(function(){
jQuery(".chosen").data("placeholder","Select Products").chosen();
});
</script>
#script in getting values from select option
<script>
function myFunction() {
var z = document.getElementById("mySelect2").value;
document.getElementById("demo2").innerHTML = z;
}
But as on the screenshot there were multiple values but when generated only 1 data that
was generated which is #10Recovery
#code on generating
<a class="button" onclick="myFunction()">{% trans 'Generate' %}</a>