當前的問題涉及創建一個選擇框,當將字段懸停在該選擇框上時,選項說明可見,而不是點選開啟options.
為了實現此功能,我們利用了JavaScript方法:如下:
$('#selectUl li:not(":first")').addClass('unselected'); // Hide the 'unselected' elements in the ul. $('#selectUl').hover( function(){ // mouse-over $(this).find('li').click( function(){ $('.unselected').removeClass('unselected'); // removes the 'unselected' style $(this).siblings('li').addClass('unselected'); // adds 'unselected' style to all other li elements var index = $(this).index(); $('select option:selected').removeAttr('selected'); // deselects the previously-chosen option in the select $('select[name=size]') .find('option:eq(' index ')') .attr('selected',true); // assumes a 1:1 relationship between the li and option elements }); }, function(){ // mouseout (or mouseleave, if they're different, I can't remember). });
在此方法中,未選擇的類別用於最初隱藏除第一個選項之外的所有選項。當 ul 懸停在上方時,未單擊的元素將被賦予未選擇的類,從而有效地消失。所選元素保持可見,其對應值反映在底層選擇欄位中。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3