简体   繁体   English

母版页链接的背景颜色在Internet Explorer中正在发生变化,但在Mozilla Firefox中无法正常工作

[英]master page link's background colour is changing in Internet explorer but not working in Mozilla Firefox

I have one link whose background colour has to change when I click on it. 我有一个链接,当我点击它时背景颜色必须改变。 So I have used a JavaScript function to do this,but it is working in Internet explorer but not changing in Mozilla Firefox. 所以我使用JavaScript函数来执行此操作,但它在Internet Explorer中工作,但在Mozilla Firefox中没有更改。

The code is below: 代码如下:

function hilite() {
    Trend.style.background= "#000000";
}

Here trend is the id of the Link tag. 这里的趋势是Link标签的id。

Link: 链接:

<a id="Trend" style="color: #FFFFFF;
 text-decoration: none;" href="ATrendAnalysis.aspx">Trend Analysis</a> &nbsp;&nbsp;

Cs file: Cs文件:

 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ScriptRegistration1", "hilite();", true);

In this case: 在这种情况下:

 Trend.style.background= "#000000";

"Trend" is a JavaScript variable, which is not defined. “趋势”是一个JavaScript变量,未定义。 This is NOT referencing an element in the DOM. 这不是引用DOM中的元素。

Use: 采用:

document.getElementById('Trend').style.background= "#000000";

You could also try to apply some styles to the link using CSS by using the pseudo-class selector :active. 您还可以尝试使用CSS通过使用伪类选择器将一些样式应用于链接:active。

:Active would apply the defined style (in your case, it would be change its background color) only while the link is being pressed. :只有在按下链接时,Active才会应用已定义的样式(在您的情况下,它将更改其背景颜色)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 母版页中的jQuery脚本在Internet Explorer中不起作用 - Jquery script in master page not working in Internet Explorer jQuery代码可在Chrome和Mozilla Web浏览器上运行,但不能在Internet Explorer上运行 - jQuery code working on Chrome and Mozilla web browser but not on Internet Explorer 单击Mozilla Firefox中的链接后,如何在Windows资源管理器中打开网络路径文件夹? - How to open a network path folder in windows explorer on click of link from Mozilla Firefox? .net单击图像按钮在Internet Explorer中不起作用,但在Firefox中 - .net click on image button not working in Internet Explorer but in Firefox Internet Explorer事件不起作用 - Internet Explorer events not working MVC 3表单身份验证在Internet Explorer中不起作用会保持重定向到登录页面 - MVC 3 Forms Authentication not working in Internet Explorer keeps redirecting to login page 我的网页在Chrome和Mozilla中是模糊的,但在资源管理器中则不是 - My web page is fuzzy in Chrome and mozilla but not in Explorer 在具有母版页的页面上添加链接标记的位置? - Where to add Link tags on a page that's got a master page? 更改堆栈中行的背景颜色 - Changing the background colour of lines in the stack Monogame-更改背景颜色错误 - Monogame - Changing background colour error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM