我想从选项标签中获取' id' 的值....如何编辑功能。每次我运行它都会提供身份信息,但我想显示价格信息
如何修改response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename=abc.csv");
ServletOutputStream out = res.getOutputStream();
for (Order traverse : orderMap.values())
{
out.write(traverse.toString().getBytes());
out.write("\n".getBytes());
out.flush();
}
这一行请建议我帮忙
var sel = document.getElementById('proID');
答案 0 :(得分:1)
检查样本以选择所选选项的属性。
$(document).on('change', '#proID', function(){
var val = $('option:selected', this).attr('value');
console.log(val);
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="proID" name="proID" >
<option>Select Product</option>
<option value="val11" id="1000">sample11</option>
<option value="val22" id="2000">sample22</option>
</select>
&#13;
答案 1 :(得分:1)
这是获取所选选项ID的id的纯JavaScript解决方案。
select = document.getElementById('proID');
var selectedOpt = select.options[select.selectedIndex];
alert(selectedOpt.id);