首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery addclass

jquery addclass
EN

Stack Overflow用户
提问于 2011-09-15 20:10:36
回答 2查看 542关注 0票数 1

这可能很简单,但我是jQuery的新手,所以……在IE 8中,即使在兼容模式下,链接颜色也不会变成粉红色。现在,如果我在firefox上运行它,chrome就可以工作了。但有一件事让我感到困惑。如果我在函数中添加了一个警告,那么在IE8中,链接会变成粉红色,并且会显示消息框。有人能解释一下这是怎么回事吗?

代码语言:javascript
复制
<%@ Page Title="Home Page" Language="C#"  AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1" runat="server">
    <title></title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<style type="text/css">
a.over {color:pink;}

</style>

<script type="text/javascript">
    $(document).ready(function () {
        $("a").mouseover(function () {
            $(this).addClass("over");
            //alert("mouseOver");
        });

        $("a").mouseout(function () {
            $(this).removeClass("over");

        });
    });

</script>
</head>
<body>
    <form id="Form1" runat="server">
    <div>
    <a class="" href="#">Link</a>
    </div>

</form>
</body>
</html>

我知道我可能只需要在我的css中添加一些类似:hover的东西,但这只是一个课本上的例子,我不能工作。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-09-15 20:19:06

尝试添加页面的doctype beggning

代码语言:javascript
复制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

更新

代码语言:javascript
复制
The doctype declaration should be the very first thing in an HTML document, before the <html> tag.

The doctype declaration is not an HTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.

The doctype declaration refers to a Document Type Definition (DTD). The DTD specifies the rules for the markup language, so that the browsers render the content correctly.
票数 2
EN

Stack Overflow用户

发布于 2011-09-15 20:24:06

我知道您可能不会问这个问题,但只需使用:hover伪类就可以了:)

代码语言:javascript
复制
a:hover { color: pink; }

另外,考虑使用jQ hover()方法和jQ toggleClass()方法:

代码语言:javascript
复制
$('a').hover(function() {
  $(this).toggleClass('over');
},
function() {
  $(this).toggleClass('over');
});

但我也同意@Kanishka的观点:使用正确的DOCTYPE对于IE来说是必不可少的

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7430566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档