初學Jquery外掛程式製作 在SageCRM的查詢螢幕隱藏部分行的功能

來源:互聯網
上載者:User

解決思路:
1、 在標題處增加一個【—】【+】號,供使用者點擊。
2、 使用者收縮和展開螢幕的行為儲存在Cookie裡面。頁面重新載入或者使用者重新登入系統,仍然能記住使用者的行為。
  
優點:1、使用Jquery外掛程式的形式來做,容易擴充。容易實現。
  2、 儲存在Cookie的行為,容易實現,減少工作量,使用者也能接收。如儲存在資料庫,則增加頁面的負載。
  缺點:不能每個頁面使用單獨行為,既是:每次使用者的收縮和擴充在系統都是全域的。並且到其他電腦登入、或者清除緩衝之後,就不能記住使用者的操作了。
  
首先使用js函數的方式實現。然後改成Jquery外掛程式:代碼
複製代碼 代碼如下:
/*
* TableToggle 0.1
* Copyright (c) 2011 Novus_lee http://www.cnblogs.com/novus
* Date: 2011-12-23
* 在SageCRM的查詢螢幕隱藏部分行的功能
*/
(function($){
$.fn.TableToggle = function(options){
var defaults = {
plussrc : "/upload/201112/20111226224658296.gif", //--[+]號圖片
minussrc : "/upload/201112/20111226224658809.gif",
line : 2
}
var options = $.extend(defaults, options);
var flip = 0, i = 0;
this.each(function(){
var $thisTable = $(this);
var claName = "btntoggle" + i;
//--所在表格的上方增加圖片按鈕
var $Title = $thisTable.parent().parent().parent().find("td.PANEREPEAT");
$Title.prepend("<a href='javascript:void(0);' class='" + claName + "' style='cursor:pointer;padding-right:10px;'><img style='border:0px;' src='" + options.minussrc + "'></a>");
var trlen = $thisTable.find("tr").length;
options.line = (options.line > trlen ? trlen : options.line);
$Title.find("a." + claName).click(function () {
$thisTable.find("tr:gt(" + options.line + ")").toggle(flip++);
if (flip % 2 == 0)
{
$Title.find("img[src*='smallplus']").attr("src",options.minussrc);
$.cookie(claName, "plus");
}
else
{
$Title.find("img[src*='smallminus']").attr("src",options.plussrc);
$.cookie(claName, "smallminus");
}
});
if ($.cookie(claName) == "smallminus" || $.cookie(claName) == "" || $.cookie(claName) == null)
{
$("a." + claName).click();
}
i++;
});
};
})(jQuery);

外掛程式還調用了一個jquery的Cookie外掛程式。
調用的方法:
複製代碼 代碼如下:
<script type="text/javascript" src="../scripts/jquery.js"></script>
<script type="text/javascript" src="../scripts/cookie.js"></script>
<script type="text/javascript" src="../scripts/toggleblock.js"></script>
<script type="text/javascript">
<!--
$(function(){
$("table.CONTENT:eq(0)").TableToggle(2);
})
//-->
</script>

效果

收縮:

展開:

PS: SageCRM是什麼只支援IE7、 IE8的。所以這裡的外掛程式並沒有測試瀏覽器安全色性。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.