不使用XPath选择符一切正常,一使用,IE(6.0)报错:undefined为空不是对象,FF无反应。
问题程序如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.a{color:lime
}
.pdf{
color:fuchsia;
}
.mailto{
color:red;
}
</style>
<script language="javascript" src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$('document').ready(function(){
$('a[@^="mailto:"]').addClass('mailto');
});
</script>
<title>改变超级链接的样式</title>
</head>
<body>
<a href="mailto:[email protected]">写信给中国第一教育网</a>
<a href="http://mail.163.com/jsp.pdf">下载PDF文件</a>
<a href="http://www.sina.com.cn">新浪网</a>
</body>
</html>
问题程序如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
.a{color:lime
}
.pdf{
color:fuchsia;
}
.mailto{
color:red;
}
</style>
<script language="javascript" src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$('document').ready(function(){
$('a[@^="mailto:"]').addClass('mailto');
});
</script>
<title>改变超级链接的样式</title>
</head>
<body>
<a href="mailto:[email protected]">写信给中国第一教育网</a>
<a href="http://mail.163.com/jsp.pdf">下载PDF文件</a>
<a href="http://www.sina.com.cn">新浪网</a>
</body>
</html>
因为xpath用的不多,影响效率,jquery1.3之后不支持xpath
需要使用插件支持
你这个可以直接写成
$('a[href^="mailto:"]').addClass('mailto');