我有一個樹形視圖,默認情況下有一個文件夾圖標,一旦點擊它就必須更改爲複選框圖標。進一步點擊複選框圖標應顯示一個文件夾圖標。javascript image toggling
示例代碼:
服務器端代碼:C#
htmlSb.AppendFormat("<li><span class=\"folder\"
onclick=\"javascript:return Test.Controls.TreeView.SelectNode('"
+ this.Id
+ "',this);\">{0}</span></li>", emptyContent);
JavaScript代碼:
var Test= new Object();
Test.Controls=new Object();
Test.Controls.TreeView = new Object();
Test.Controls.TreeView.SelectNode = function (TreeId, nodeLabel) {
$("#" + TreeId + " li span, ul li span").css("background-color", "transparent");
nodeLabel.style.backgroundColor = "white";
nodeLabel.style.background = "url(../images/selected.gif) 0 0 no-repeat";
}
另一圖像:
if (nodeLabel.style.background = "url(../images/folderclosed.gif) 0 0 no-repeat")
我需要"selected.gif"
和"folderclosed.gif"
圖像之間切換。如果點擊了另一個應該顯示。反之亦然。
請幫忙。
對不起亞歷克斯,我是一名新成員,我不知道this.I've目前標誌着接受的答案。 感謝您指出。 – SRA 2010-06-15 06:35:22