jQuery-Select list option hover

前端 未结 3 1721
旧巷少年郎
旧巷少年郎 2020-12-02 01:48

I want to alert an option when the mouse-cursor is over it. I use this code:

$(\"select > option\").hover(function ()
    { 
        alert($(this).attr(\"         


        
3条回答
  •  天涯浪人
    2020-12-02 02:31

    You can try this.

    $("select").hover(function (e)
    {
         var $target = $(e.target); 
         if($target.is('option')){
             alert($target.attr("id"));//Will alert id if it has id attribute
             alert($target.text());//Will alert the text of the option
             alert($target.val());//Will alert the value of the option
         }
    });
    

提交回复
热议问题