本文主要介绍了jquery动态移除和添加背景图片的方法,结合实例形式分析了jquery针对页面元素样式及事件响应的动态操作技巧,需要的朋友可以参考下,希望能帮助到大家。
利用jquery移除和添加图片
1、样式
<style type="text/css">
.changeimage{
background:url(images/right.png) no-repeat center;
}
</style>
2、js
(1)在改变标签的样式,需要移除之前添加的样式
$("#tab tr").find("td").removeclass("changeimage");
(2)添加样式
$("#tab tr").find("td").addclass("changeimage");
附:完整示例demo:
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>jquery移除和添加图片</title>
<script type="text/javascript" src="jquery-1.7.2.min.js" ></script>
<style type="text/css">
.changeimage{
background:url(images/arrow1.gif) no-repeat center;
}
</style>
<script>
function removeimg(){
$("#tab tr").find("td").removeclass("changeimage");
}
function addimg(){
$("#tab tr").find("td").addclass("changeimage");
}
</script>
</head>
<body>
<table border=1 id="tab">
<tr><td>年</td><td>制造商</td><td>型号</td><td>说明</td><td>价值</td></tr>
<tr><td>1997</td><td>ford</td><td>e350</td><td>"ac</td><td> abs</td><td> moon"</td><td>3000.00</td></tr>
<tr><td>1999</td><td>chevy</td><td>"venture ""extended edition"""</td><td>""</td><td>4900.00</td></tr>
<tr><td>1999</td><td>chevy</td><td>"venture ""extended edition</td><td> very large"""</td><td>""</td><td>5000.00</td></tr>
<tr><td>1996</td><td>jeep</td><td>grand cherokee</td><td>"must sell!</td></tr>
<tr><td>air</td><td> moon roof</td><td> loaded"</td><td>4799.00</td></tr>
</table>
<input type="button" value="添加样式" onclick="addimg()"/>
<input type="button" value="删除样式" onclick="removeimg()"/>
</body>
</html>
相关推荐:
使用css给未知宽高的元素添加背景图片方法
如何在php文件中添加背景图片
css奇特用法之 img添加背景图片配合显示效果惊艳_html/css_web-itnose
以上就是jquery动态移除和添加背景图片实例详解的详细内容。