仅使用jQuery UI类中的一个元素

时间:2016-01-09 14:21:11

标签: jquery

如何更改当前按钮(单击时),而不是页面上的所有按钮,其中shold我放了“this”元素

$(document).ready(function() {
  $(function() {
    // run the currently selected effect
    function runEffect() {
      // get effect type from
      var selectedEffect = "blind";
      // most effect types need no options passed by default
      var options = {};
      // some effects have required parameters
      // run the effect
      $( ".button" ).toggle( selectedEffect, options, 1000);

    }; 
    // set effect from select menu value   
    $('.moreshide').click(function(){
      $(this).toggleClass('oks');
      runEffect();
    });
  });           
});

1 个答案:

答案 0 :(得分:0)

您必须将clicked元素的引用传递给runEffect函数。然后在该部分中找到最近的部分ID和按钮类。

function runEffect(obj) {
  // get effect type from
  var selectedEffect = "blind";
  // most effect types need no options passed by default
  var options = {};
  // some effects have required parameters
  // run the effect
  $(obj).closest('#chef').find(".button").toggle(selectedEffect, options, 1000);                    
}; 

$('.moreshide').click(function(){
      $(this).toggleClass('oks');
      runEffect(this);
});