简体   繁体   English

麻烦更改链接悬停背景颜色

[英]Trouble changing link hover background-colour

This should be a simple thing to do, but I cant seem to change the hover background-color on the tweets on the following page: 这应该是一件简单的事情,但是我似乎无法在下一页的推文上更改悬停background-color

http://www.studiopsk.com/news.html http://www.studiopsk.com/news.html

All the other links are fine, but the ones on the latest tweets won't seem to change? 其他所有链接都很好,但是最新推文上的链接似乎不会改变?

Using this to try... 用这个来尝试...

<script>
    if(sessionStorage.getItem("visited") != "true"){
var colors = Array("#A3F8EF", "#FF7275", "#CBB6E7", "#FF9D74", "#FDF874"), idx;
idx = Math.floor(Math.random() * colors.length); // Pick random index
sessionStorage.setItem("colour", colors[idx]);
newColour = sessionStorage.getItem("colour");
}
newColour = sessionStorage.getItem("colour");

$("div.tweets_txt a").hover(function(){
  $(this).css("background-color", newColour+"!important");
}, function() {
  $(this).css("background-color","transparent");
});  
sessionStorage.setItem("visited", "true");
</script> 

It's a bit unclear what you're trying to accomplish, and I think just setting a class on the elements based on situation will make your life easier. 尚不清楚您要完成什么,我认为仅根据情况在元素上设置类将使您的生活更轻松。 But it appears that you're talking about the problem being for new elements added to the page, if that's the case, it appears that you are using javascript that's being executed in HTML, and not on any event, just on page load, which means it will only run once, at page load. 但是似乎您正在谈论的问题是添加到页面的新元素,如果是这种情况,则似乎您使用的是在HTML中执行的javascript,而不是在任何情况下(仅在页面加载时)表示它只会在页面加载时运行一次。 And won't effect any elements added to the page dynamically at a later time. 并且以后不会影响动态添加到页面中的任何元素。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM