0
如何在ASP.NET TreeView中點擊任何一個子元素時保持背景色?當鼠標點擊treeview子元素時保持背景色
如何在ASP.NET TreeView中點擊任何一個子元素時保持背景色?當鼠標點擊treeview子元素時保持背景色
使用treenodedatabound事件樹視圖,並添加每個項目onclick事件調用javascript函數做任何你想做
protected void TreeView1_TreeNodeDataBound(object sender, TreeNodeEventArgs e)
{
e.Node.Text = "<span onclick='javascript:MyFunction(this);'>Text</span>";
}
,或者你可以用這種方式
Dim deletenode As New TreeNode("<span onclick=""javascript:confirm('Are you sure you want to delete this ?');"">Delete</span>", "0" & dr("ProjectID"))
新增的項目
Js功能樣本
MyFunction(sender) {
//using jquery you have the html element (td) you can get any value from that element based on your senario
//for example you have attribute called x holding the value you want
alert($(sender).attr("x"));
//or to change the background color
$(sender).css("background-color" , "blue");
}
您可以提供'javascript:MyFunction(this);功能? – user274139 2010-02-18 06:21:10
function MyFunction(sender) //使用jquery你有html元素(td)你可以從該元素得到任何值,這取決於你的senario //例如你有屬性叫做x,持有你想要的值 alert ($(sender).attr(「x」)); //或更改背景顏色 $(sender).css(「background-color」,「blue」); } – 2010-02-18 06:27:39
我不確定語法 sender.style.backgroundColor ='red'; – 2010-02-18 07:01:24