点击应该在另一个停滞的显示样式,但它不会改变,请帮忙!
我可以制作一个不同且更紧凑的代码吗?
HTML CODE:
<tr onclick="NewToggleLayer('layer_{$ban_list.bid}')" style="background: #DBF4D7" class='list'>
<td class="_center"><img alt="{if $ban_list.mod == "html"}{"_WEB"|lang}{else}{$ban_list.mod|lang}{/if}" title="{if $ban_list.mod == "html"}{"_WEB"|lang}{else}{$ban_list.mod|lang}{/if}" src="images/games/{$ban_list.mod}.gif" /></td>
<td>{$ban_list.ban_created|date_format:"%Y-%m-%d"}</td>
<td><img alt="" src="images/country/{if $ban_list.cc}{$ban_list.cc|lower}{else}clear{/if}.png" /> {$ban_list.player_nick}</td>
<td>{$ban_list.admin_nick}</td>
<td>{$ban_list.ban_reason}</td>
<td>
{if $ban_list.ban_length>0}
{$ban_list.ban_length*60|date2word:true}
{else}
{"_PERMANENT"|lang}
{/if}
</td>
{if $ban_page.show_comments == 1 && $vars.use_comment == 1}<td class="_center">{$ban_list.comment_count}</td>{/if}
{if $ban_page.show_demos == 1 && $vars.use_demo == 1}<td class="_center">{$ban_list.demo_count}</td>{/if}
{if $ban_page.show_kicks == 1}<td class="_center">{$ban_list.kick_count}</td>{/if}
</tr>
<tr id="layer_{$ban_list.bid}" style="display:none;">
blah blah
</td>
这是java函数:
function ToggleLayer(obj) {
if (document.all) {
if (document.all[obj].style.display == 'none') {
document.all[obj].style.display = 'block';
} else {
document.all[obj].style.display = 'none';
}
} else {
if (document.getElementById(obj).style.display == 'none') {
if (document.getElementById(obj).tagName == 'DIV') {
document.getElementById(obj).style.display = 'block';
} else {
document.getElementById(obj).style.display = 'table-row';
}
} else {
document.getElementById(obj).style.display = 'none';
}
}
}
function NewToggleLayer(element) {
var e = $('#' + element);
if (e.css('display') == 'none') {
e.show().find('div').slideDown('slow')
} else {
e.find('div').slideUp('slow', function () {
$(this).parent().parent().hide();
})
}
} /* Version checker */
$(function () {
var chkver = document.createElement("script");
chkver.type = "text/javascript";
chkver.async = true;
chkver.src = "//version.gm-community.net/amxbans.js";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(chkver, s);
});
function setLastVersion(ver) {
if (parseFloat($('#version').text()) < ver) {
$('#version').addClass('MustUpdate').append('text');
}
}
如何缩短功能并缩小功能?
答案 0 :(得分:0)
function ToggleLayer(obj) {
var $element = $(obj);
$element.toggle(); // if hidden then will show otherwise hide
// or $element.slideToggle();
}
function NewToggleLayer(element) {
var e = $('#' + element);
if (!e.is(':visible')) {
e.show().find('div').slideDown('slow')
} else {
e.find('div').slideUp('slow', function () {
$(this).parent().parent().hide();
})
}
}