一個基於jQuery的簡單樹形菜單

來源:互聯網
上載者:User

在工作中的項目使用的是一個前端基於 jQuery easyui 的一個系統,其中左側的主菜單使用的是 easyui 中的 tree 組件,不是太熟悉,不過感覺不是太好用。

比如 easyui 中的 tree 需要單擊分叉節點前的小三角,才能夠展開或關閉節點。另外,它還必需要求瀏覽器在相容模式下才能正常使用(這個項目中使用的 easyUI 是 1.2.2 版本,新版的 Tree 不存在該問題),很是不方便。

想修改又無從下手,所以有單獨寫一個簡單的樹形菜單的想法,趁下班的時間,抽空寫了一個簡單的JS檔案,基於jQuery1.6版本的 SimpleTree。

 

SimpleTree使用起來比較方便,它實現了最基本的樹形菜單的功能,包括1個JS檔案、1個CSS檔案和5個表徵圖檔案。

使用時只要將相關檔案複製到項目中,並在相應的頁面引用它就行,例如:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>SimpleTree</title>
<link rel="stylesheet" type="text/css" href="js/tree_themes/SimpleTree.css"/>
<script type="text/javascript" src="js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="js/SimpleTree.js"></script>
<script type="text/javascript">
$(function(){
$(".st_tree").SimpleTree({
click:function(a){
if(!$(a).attr("hasChild"))
alert($(a).attr("ref"));
}
});
});
</script>
</head>
<body>

<div class="st_tree">
<ul>
<li><a href="#" ref="hyjm">歡迎介面</a></li>
<li><a href="#" ref="xtgl">系統管理</a></li>
<ul show="true">
<li><a href="#" ref="yhgl">使用者管理</a></li>
<li><a href="#" ref="rzck">日誌查看</a></li>
</ul>
<li><a href="#" ref="ckgl">倉庫管理</a></li>
<ul>
<li><a href="#" ref="kcgl">庫存管理</a></li>
<li><a href="#" ref="shgl">收貨管理</a></li>
<li><a href="#" ref="fhgl">發貨管理</a></li>
<ul>
<li><a href="#" ref="yhgl">使用者管理</a></li>
<li><a href="#" ref="rzck">日誌查看</a></li>
</ul>
</ul>
</ul>
</div>

</body>
</html>

上面代碼在IE8中執行結果

在Chrome裡執行

 

樣本程式下載:SimpleTree1.0.zip 

11.27更新1.1版本:SimpleTree1.1.zip

11.27更新1.2版本:SimpleTree1.2.zip

12.04更新1.3版本: http://files.cnblogs.com/zhhh/SimpleTree1.3.zip

(程式在使用中不斷功能更新,並虛心接受各種意見和建議)

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.