我想在点击它时更改链接的颜色 [英] I want to change the color of link when click on it
本文介绍了我想在点击它时更改链接的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在c#中使用代码来打印链接。请建议如何在访问时更改链接的颜色。
我尝试过:
我在c#中使用代码来打印链接。请建议如何在访问时更改链接的颜色。
< pre> for(int ar = 0; ar< arrProcess.Length; ar ++)
{
LinkButton lnk = new LinkButton();
lnk.ID =lnk+ listItemIds;
lnk.ClientIDMode = ClientIDMode.Static;
lnk.Click + = new System.EventHandler(this.colorClick);
lnk.Text = arrProcess [ar];
lnk.Attributes.Add(onClick,changeControlStyle('+ lnk.ClientID +');); //这是为了防止页面重新加载$ b $ b listItemIds ++;
PlaceHolder1.Controls.Add(lnk); //在PlaceHolder中添加LinkButton
//PlaceHolder1.Controls.Add(new LiteralControl(< br />));
}
解决方案
我找不到ASP.NET LinkButton的现场演示,看看它的HTML输出是什么。但是,有两种可能性。
A)LinkButton的HTML输出是标签。在这种情况下使用a:Visited {...} CSS类,这是一个很好的教程:https://css-tricks.com/almanac/selectors/v/visited/
B)如果LinkButton生成标签,那么我认为没有可以应用的直接CSS规则集。在这种情况下,您可能需要编写一些JS代码来处理这种情况。这是一个例子:https://stackoverflow.com/questions/54545567/how-to-change-the-background-color-of-a-visited-button-in-css
*我对ASP.NET的了解非常过时,但您可能希望使用OnClientClick()将JS代码连接到这些按钮:https://docs.microsoft.com/en-us/dotnet /api/system.web.ui.webcontrols.button.onclientclick?view=netframework-4.8
i am using code in c# to print the link. please suggest how to change the color of link when visited on it.
What I have tried:
i am using code in c# to print the link. please suggest how to change the color of link when visited on it. <pre> for (int ar = 0; ar < arrProcess.Length; ar++) { LinkButton lnk = new LinkButton(); lnk.ID = "lnk" + listItemIds; lnk.ClientIDMode = ClientIDMode.Static; lnk.Click += new System.EventHandler(this.colorClick); lnk.Text = arrProcess[ar]; lnk.Attributes.Add("onClick", "changeControlStyle('" + lnk.ClientID + "');"); //This is to prevent the page to reload listItemIds++; PlaceHolder1.Controls.Add(lnk); // Adding the LinkButton in PlaceHolder //PlaceHolder1.Controls.Add(new LiteralControl("<br />")); }
解决方案
I cannot find a live demo of ASP.NET LinkButton to see what's the HTML output for it. But, there are 2 possibilities.
A) The HTML output of LinkButton is an tag. In this case use the a:Visited{...} CSS class, here is a good tutorial: https://css-tricks.com/almanac/selectors/v/visited/
B) If LinkButton generates a tag, then I don't think there is a direct CSS rule set that you can apply. In that case, you may need to write some JS code to handle the situation. Here is an example: https://stackoverflow.com/questions/54545567/how-to-change-the-background-color-of-a-visited-button-in-css
* My knowledge on ASP.NET is very outdated, but you may want to use OnClientClick() to wire the JS code to these buttons: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.button.onclientclick?view=netframework-4.8
这篇关于我想在点击它时更改链接的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文