当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery动态移除和添加背景图片的方法详解

jQuery动态移除和添加背景图片的方法详解

2019年03月22日  | 移动技术网IT编程  | 我要评论

本文实例讲述了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>

更多关于jquery相关内容感兴趣的读者可查看本站专题:《jquery图片操作技巧大全》、《jquery表格(table)操作技巧汇总》、《jquery切换特效与技巧总结》、《jquery扩展技巧总结》、《jquery常用插件及用法总结》、《jquery常见经典特效汇总》及《jquery选择器用法总结

希望本文所述对大家jquery程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网