使用d3获取事件侦听器中输入元素的值
问题描述:
我有两个html元素:
I have two html elements:
<input id="searchInput">
<div id="searchText"></div>
我使用d3在脚本中添加监听器。
I'm using d3 to add a listener in a script.
d3.select("#searchInput").on("keyup",getSearchText);
我需要一个将输入值输出到div的函数
I need a function that prints a value of input to a div
function getSearchText(value) {
d3.select("#searchResults").html(value.toString());
}
但我不知道如何将输入值参数传递给侦听器函数。
But I don't know how to pass input value parameter to a listener function.
答
尝试使用
的实例获取值:
Try using an instance of this
to get the value:
d3.select("#searchResults").html(this.value);