我有一个 Jquery 切换器,其中包含一个 MySQL 表的输入表单。
在这个开关的正下方,我在列表中显示数据。
我想做的是让切换处于打开状态(删除“display:none”),如果表没有记录。如果表确实包含记录,当然会关闭。
为了让事情变得更复杂,我的表被硬过滤到登录用户,所以如果表上没有与登录用户匹配的记录,我只希望切换默认为打开状态。
我希望这是有道理的!
我的 PHP 知识充其量只是一点点,所以请放轻松。
这是我的切换代码:-
(function($) { $.fn.simpleToggle = function(opts) {
var options = $.extend({}, $.fn.simpleToggle.defaults, opts);
return this.each(function() {
$title = $(this).children('.togTitle');
$title.each(function() {
$(this).click( function() {
$item = $(this);
$item.next('.togDesc').slideToggle('fast', function() {
$icon = $item.children('.iconSymbol');
if ($(this).css('display') == 'block') {
$icon.removeClass('plus').addClass('minus');
} else {
$icon.removeClass('minus').addClass('plus');
}
});
});
});
});
}
$.fn.simpleToggle.defaults = {}
})(jQuery);
最佳答案
很难想象底层的 dom。
但是,像这样的东西可以解决问题:
(function($) { $.fn.simpleToggle = function(opts) {
var options = $.extend({}, $.fn.simpleToggle.defaults, opts);
return this.each(function() {
$title = $(this).children('.togTitle');
$title.each(function() {
$('.togDesc', this).each( function () {
if ( $(this).children('.iconSymbol').length == 0 ) {
$(this).show();
}
});
$(this).click( function() {
$item = $(this);
$item.next('.togDesc').slideToggle('fast', function() {
$icon = $item.children('.iconSymbol');
if ($(this).css('display') == 'block') {
$icon.removeClass('plus').addClass('minus');
} else {
$icon.removeClass('minus').addClass('plus');
}
});
});
});
});
}
$.fn.simpleToggle.defaults = {}
})(jQuery);
关于php - 根据 mySQL 数据更改 jquery 切换的打开状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7071978/