function dynAddOption(list, elementToBeAdded){
if( list.length > 0) {
for(var index = 0; index < list.length; index ++){
elementToBeAdded.options[index + 1] = new Option(list[index].description, list[index].id);
}
}
}
如何为每个<option>
提供工具提示?
答案 0 :(得分:3)
从this question可以看出,您只需要添加title
属性即可。在这种情况下,这应该有效:
function dynAddOption(list, elementToBeAdded){
if (list.length > 0) {
for(var index = 0; index < list.length; index ++) {
var opt = new Option(list[index].description, list[index].id);
opt.title = 'Foo'; // < this is the tooltip
elementToBeAdded.options[index + 1] = opt;
}
}
}