@zzudhj
2016-06-22T03:39:12.000000Z
字数 796
阅读 913
html 点击button 更换背景
js实现方法
监听id的ontouchstart、ontouchend事件
当然除了使用对象的id之外,也可以使用class,不过需要对获得的class对象的数组进行遍历
<script type="text/javascript">window.onload = function() {var id = document.getElementById("id");// 触摸id.ontouchstart = function() {// 背景变绿this.style.backgroundColor = "green";};// 停止触摸id.ontouchend = function() {// 还原白色this.style.backgroundColor = "white";};};</script>
使用jquery实现
$(function() {$(".classdiv").on("touchstart", function() {$(this).css({background: "green"});}).on("touchend", function() {$(this).css({background: "white"});});});
使用jquery设置css方法
$(this).css({// 背景颜色backgroundColor: "#0f0",// 背景图片backgroundImage: "url(图片地址.png)",// 背景图片大小backgroundSize: "50% 50%",// 背景图片定位backgroundPosition: "50px 20px",// 背景图片重复backgroundRepeat: "no-repeat"});// 设置带有参数url方法Z('.className').css("background-image",'url("'+parameter+'")');