e.Row.Attributes.Add「建议收藏」

发布时间:2025-12-09 13:58:01 浏览次数:4

其实看到属性这个单词,还有点发憷呢,C#里面有个关键词是Attributes, 搞了半天貌似没有弄清楚

e.Row.Attributes.Add()函数的介绍,包括参数,什么是Attributes

就是往行里面添加属性
相当于html里面的一个表里的一个行的属性,你看看那个属性有什么,这个就可以添加什么属性
//这个就是在前台添加一个Button的按钮,然后给他添加事件
 <asp:Button ID="Button1" runat="server" Text="Button" /> //为Button1添加onclick()事件 ,Button为服务器控件 Button1.Attributes.Add("onclick", "return checkSame()"); <head> <title></title>  <script type="text/javascript" > function checkSame() { var d = document.getElementById("las"); alert(456789) //d.innerText = 456; return 5; } document.getElementById("las45").innerHTML = checkSame(); </script> </head> 

  


一般用到的最多的是什么鼠标移入和移除

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { int i; //执行循环,保证每条数据都可以更新 for (i = 0; i < GridView1.Rows.Count; i++) { //首先判断是否是数据行 if (e.Row.RowType == DataControlRowType.DataRow) { //当鼠标停留时更改背景色 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'"); //当鼠标移开时还原背景色 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c"); //点击一个当前行出现弹出框 e.Row.Attributes.Add("onclick", "alert(123)"); e.Row.Attributes.CssStyle.Add("cursor", "hand"); } } }

  然后就是add(“属性”,”结果”);

<!DOCTYPE html><html><body>获取 js中函数的返回值<p>本例调用的函数会执行一个计算,然后返回结果:</p><p ></p><script>function myFunction(a,b){return a*b;}document.getElementById("demo").innerHTML=myFunction(4,3);</script></body></html>

  

这个讲的全

C#中 Attributes的用法

C#中在后台给前台代码添加样式

JS中Attribute的详解

var d = document.getElementById("sss").setAttribute("good", "hello");    alert(document.getElementById("t").innerHTML)    var d = document.createAttribute("good");    document.getElementById("sss").setAttributeNode(d);    alert(document.getElementById("t").innerHTML);
//<input type="hidden" value="aaa" good="">

  

转载于:https://www.cnblogs.com/ZkbFighting/p/9248279.html

需要做网站?需要网络推广?欢迎咨询客户经理 13272073477