ily*_*lyo 0 javascript jquery jquery-ui
我有以下使用jQuery UI功能:
$('.droppable').droppable({
    tolerance: 'touch',
    over: function () {
        var hasHiddenList = $(this).children('ul.hidden');
        if (hasHiddenList.length)
            hasHiddenList.removeClass('hidden');
    },
    out: function () {
        var hasEmptyList = $(this).children('ul.empty');
        if (hasEmptyList.length)
            hasEmptyList.addClass('hidden');
    },
    drop: function () {
        var hasEmptyList = $(this).children('ul.empty');
        if (hasEmptyList.length)
            hasEmptyList.removeClass('empty');
    }
});
我想知道我是否可以定义变量hasHiddenList和hasEmptyList回调函数之外,因为它在所有变量中都是相同的变量.
更好的是,你甚至不需要if语句和变量:
$('.droppable').droppable({
    tolerance: 'touch',
    over: function () {
      $(this).children('ul.hidden').removeClass('hidden');
    },
    out: function () {
      $(this).children('ul.empty').addClass('hidden');
    },
    drop: function () {
      $(this).children('ul.empty').removeClass('empty');
    }
});
| 归档时间: | 
 | 
| 查看次数: | 68 次 | 
| 最近记录: |