如何设置< select>的值?元素,使用D3.js?
我正在尝试这个:@H_404_3@
d3.select('#myselect').attr('value','France');
但它没有用.@H_404_3@
JSFiddle:http://jsfiddle.net/06z9tnzs/@H_404_3@
解决方法
您需要使用property而不是attr来设置值.
d3.select(‘#myselect’).property(‘value’,’France’);@H_404_3@
来自d3文档:@H_404_3@
Some HTML elements have special properties that are not addressable using standard attributes or styles. For example,form text fields have a value string property,and checkBoxes have a checked boolean property. You can use the property operator to get or set these properties,or any other addressable field on the underlying element,such as className.@H_404_3@
https://github.com/mbostock/d3/wiki/Selections#property@H_404_3@
关于你的JSFiddle缺少d3.js引用而没有在select元素上指定“myselect”的id,Albert的注释也是正确的.@H_404_3@