jQuery figuring out if parent has lost 'focus'

后端 未结 7 1917
小鲜肉
小鲜肉 2020-12-16 05:39

I\'m stuck on figuring out the logic to make a drop down menu keyboard accessible.

The HTML is structured as such (extra class names used for clarity):



        
7条回答
  •  醉话见心
    2020-12-16 06:20

    I had a similar issue... I created a jsfiddle to determine when a parent fieldset loses focus and then calling a function. It could certainly be optimized, but it's a start.

    http://jsfiddle.net/EKhLc/10/

    function saveFields() {
      $.each($('fieldset.save'),function(index, value) {
        // WHERE THE POST WOULD GO
        alert('saving fieldset with id '+ value.id);
        $(value).removeClass('save');
      });
    
    }
    $('.control-group').focusin(function(){
      var thefield = $(this).parent('fieldset');
      if (!thefield.hasClass('active')) {
        if($('fieldset.active').length > 0){
    
          $('fieldset.active').removeClass('active').addClass('save');
          saveFields();
          }
        thefield.addClass('active');
        } else {
            console.log('already active');
        }
    });
    

提交回复
热议问题