2014-01-30 84 views
-2

點擊應該停滯在另一個顯示樣式,但它不會改變,請幫助!jquery不改變樣式顯示

我可以製作不同的更緊湊的代碼嗎?

HTML代碼:

        <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'); 
    } 
} 

如何縮短功能,使小?

+5

*「這是java函數:」*不,這是* JavaScript *函數。 Java!= JavaScript –

+2

查看你的問題片刻,特別是標記格式和代碼格式。明確?易於閱讀? –

+0

您的JavaScript代碼是......無法讀取的 – Damax

回答

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(); 
     }) 
    } 
}