D3.js:获取所选选项的值? [英] D3.js: get value of selected option?

查看:190
本文介绍了D3.js:获取所选选项的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从D3.js中的下拉列表中获取所选选项的值。

I want to get the value of the selected option from a dropdown list, in D3.js.

<select>
<option data-graph="1">1</option>
<option value="2">2</option>
</select>

我看过这个问题,它解释了当选择更改时如何获取值:

I have seen this question which explains how to get the value when the select changes:

d3.select("#myselect").on("change", change)
function change() {
    this.options[this.selectedIndex].value
}

但是如何在页面加载时获取所选的值,

But how can I get the selected value on page load, not when the select is changed?

推荐答案

您不需要使用D3:

var sel = document.getElementById('myselect');
console.log(sel.options[sel.selectedIndex].value)

这篇关于D3.js:获取所选选项的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆