<!DOCTYPE html>
<html>
<head>
<style>
div { color:red; text-align:center; cursor:pointer;
font-weight:bolder; width:300px; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<div>Click here</div>
<div>to iterate through</div>
<div>these divs.</div>
<script>
$(document.body).click(function () {
$("div").each(function (i) {
if (this.style.color != "blue") {
this.style.color = "blue";
} else {
this.style.color = "";
}
});
});</script>
</body>
</html>
if ($(this).is("#stop")) {
$("span").text("Stopped at div index #" + index);
return false;
}
<script>
$("button").click(function () {
$("div").each(function (index, domEle) {
// domEle == this
$(domEle).css("backgroundColor", "yellow");
if ($(this).is("#stop")) {
$("span").text("Stopped at div index #" + index);
return false;
}
});
});
</script>
分享到:
相关推荐
$.each([1,2,3,4],function(){ //$(this)==数组中的每一个数组(如果数组是对象,就是对象) }); 方法三 应有场景有点不一样 this.each(function(){ }) 扩展jQuery对象方法 应该是 j
表格升缩jquery 源代码 $(document).ready(function(){ $(".hdw").click(function(){ ... $(this).toggleClass("selected") .siblings('.child_'+this.id).toggle(); }).click(); });
$option.toggleClass("option-sel"); $("#musicClick")[0].play(); }); $("#submit").on("click",function(){ var $btn = $(this); $("#musicClick")[0].play(); if($btn.hasClass("disabled")) ...
$.toggleClass( class [, switch] ), .toggleClass( fn(index, class) [, switch] ) HTML, text str.html( ) $.html( val ), .html( fn(index, html) ) str.text( ) $.text( val ), .text( fn(index, html) ) Value ...
$.each($(this).children(".portlet"), function(d) { //alert($(this).attr('id')) list += $(this).attr('id') + "@"; }) list += "|"; //alert($(this).child(".portlet")[0].attributes['id'].value) //...
$(document).click(function(){ $('.nav-list').removeClass('open') }) $('.nav-menu,.nav-list').click(function(e){e.stopPropagation()}) $('nav').find('.nav-menu').click(function(e){ $('.nav-...
jQuery CSS3弹性工具栏伸缩菜单代码是一款效果不错的默认只显示一个圆形按钮,单点击按钮时,子菜单项会以弹性动画展开... $(this).toggleClass( "active" ); $(".icons").toggleClass( "open" ); }); [removed]
$(document).click(function(){ $('.nav-list').removeClass('open') }) $('.nav-menu,.nav-list').click(function(e){e.stopPropagation()}) $('nav').find('.nav-menu').click(function(e){ $('.nav-...
jQuery.toggleClass() 函数详解
js代码 [removed] const button = document.querySelector('.button'); const submit = document.querySelector('.submit');...function toggleClass() { ... this.classList.toggle('active');.../body>
toggleClass ( document . body , 'king' ) ;aristocrat . hasClass ( document . body , 'king' ) ;下载请参阅了解生产就绪版本。地位准备好。浏览器支持经各种制造商在 IE6 和更新的浏览器中测试。依赖关系没有...
js代码 [removed] const button = document.querySelector('.button');.../body> css3点击提交按钮加载进度条动画特效是一款简单美观的css3点击表单提交按钮、显示图标加载进度条的按钮加载动画特效。
工具浏览器及特性检测 $.support $.browser $.browser.version $.boxModel 数组和对象操作 $.each(object, [callback]) $.extend([d],tgt,obj1,[objN]) $.grep(array, fn, [invert]) $.makeArray(obj) $.map(array, ...
jQuery 1.11.0 速查表 核心 jQuery 核心函数 jQuery([sel,[context]]) ... jQuery(callback) jQuery.holdReady(hold) ... $.each(object,[callback]) $.extend([d],tgt,obj1,[objN]) $.grep(array,fn,[invert]) ...
CSSClass 是一个 JavaScript 微框架,它将函数 .hasClass、.addClass、.removeClass 和 .toggleClass 添加到 Element 原型中。 使用很简单。 包含脚本文件并仅使用函数(它们可以链接)。 您还可以通过在它们之间...
$(this).toggleClass("active"); return false; }); }); $(function () { $('.fade').hover( function() {$(this).fadeTo("slow", 0.5);}, function() {$(this).fadeTo("slow", 5); }); }); [removed]