hasClass:檢查當前元素是否含有某個特定的類,如果有,就返回true。
下載本地,做外部鏈接:<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
HTML結構:
<div class="protected"></div><div class="er"></div>
have和has的用法口訣。CSS代碼:
?//這里注意div容器要設置絕對定位!
.protected { width:100px; height:100px; background:#ff0; position:absolute; z-index:50; }
.er { width:100px; height:100px; background:#f00; position:absolute; z-index:50; top:200px; }
jQuery代碼:
<script type="text/javascript">$(document).ready(function(){$("div").click(function(){if ($(this).hasClass("protected")){$(this).animate({ left: -10 }).animate({ left: 30 }).animate({ left: -10 }).animate({ left: 30 }).animate({ left: 0 });}});})</script>
?
?
have has 的用法。?