jquery属性选择器

时间:2023-03-09 17:21:04
jquery属性选择器
<!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>
<title>属性选择器</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
.yang{ border-collapse: collapse; width:500px;height:30px;border:1px solid red;"}
</style>
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
/*
[attribute] :匹配具有指定属性的元素
[attribute=value] :匹配属性为指定值的元素
[attribute!=value] :匹配属性值不等于指定值的元素
[attribute^=value] :匹配属性值以指定值开始的元素
[attribute$=value] :匹配属性值以指定值结束的元素
[attribute*=value] :匹配属性值中包含指定值的元素
[selector1][selector2][selectorN] :同时指定多个匹配条件
*/
window.onload=function(){
$('#btnOk').click(function(){
//匹配具有color属性的font并把内容改为jquery
//$('font[color]').html('jquery'); //:匹配属性为指定值的元素
//$("font[color='#667788']").html('颜色'); // 匹配属性不为指定值的元素
$("font[color!='#667788']").html('颜色');
});
};
</script>
</head>
<body>
<font>字体1</font>
<hr />
<font color="#336699">字体2</font>
<hr />
<font color="#667788">字体3</font>
<hr />
<font color="#338899">字体4</font>
<hr />
<font color="#FFAA99">字体5</font>
<hr />
<hr/>
<input type="button" id='btnOk' value='确定' />
</body>
</html>