简体   繁体   中英

How to show tooltips for a html select list by using keyboard instead of mouse?

i have created the following html code and JQuery Script

<select id="myId" name="myName" onmouseover="createToolTip('myName')">
    <option value="value_1" title="My first tooltip">option to select 1</option>
    <option value="value_2" title="My second tooltip">option to select 2</option>
    <option value="value_3" title="My third tooltip">option to select 3</option>
    <option value="value_4" title="My fourth tooltip">option to select 4</option>
</select>

function createToolTip(name){   

    var tooltips = {
        'value_1': 'option to select 1',
        'value_2': 'option to select 2',
        'value_3': 'option to select 3',
        'value_4': 'option to select 4'
    };

    var selector = "[name=" + name + "] option";                    
    jQuery(selector).each(function() {
        $(this).attr('title', tooltips[$(this).val()]);
    });         
};

If i scroll with my mousecursor over the option field, a specific tooltip for this option element will be visible.

But is it possible to show a tooltip, if i only navigate with the keyboard (arrow cursors) over the option list? Or is a tooltip only visible, if i use my mouse? Which event must be used for this (onfocus doesn´t work for example)

Thanks !

How about onfocus event ? Did you try it. I believe onfocus would work both with mouse as well as keyboard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM