Get value of input element in event listener with

2019-02-15 17:58发布

I have two html elements:

<input id="searchInput">
<div id="searchText"></div>

I'm using d3 to add a listener in a script.

d3.select("#searchInput").on("keyup",getSearchText);

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.

2条回答
做自己的国王
2楼-- · 2019-02-15 18:16

I've found solution:

d3.select("#id").node().value
查看更多
不美不萌又怎样
3楼-- · 2019-02-15 18:18

Try using an instance of this to get the value:

d3.select("#searchResults").html(this.value);
查看更多
登录 后发表回答