admin管理员组文章数量:1290313
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.
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.
Share Improve this question edited Jan 20, 2020 at 18:28 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 8, 2013 at 13:26 nextstopsunnextstopsun 4738 silver badges14 bronze badges 3-
Not too familiar with
d3
, but shouldn'tthis.value
give you the value? – tymeJV Commented Jul 8, 2013 at 13:30 - Tried that. d3.select("#searchInput").value returns undefined. – nextstopsun Commented Jul 8, 2013 at 13:41
-
1
No no, try using
d3.select("#searchResults").html(this.value);
– tymeJV Commented Jul 8, 2013 at 13:43
3 Answers
Reset to default 4I've found solution:
d3.select("#id").node().value
Try using an instance of this
to get the value:
d3.select("#searchResults").html(this.value);
Use the third argument:
function getSearchText(d, i, o) {
const myValue = o[0].value;
}
本文标签: javascriptGet value of input element in event listener with d3Stack Overflow
版权声明:本文标题:javascript - Get value of input element in event listener with d3 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741497591a2381905.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论