$(document).ready(function() {
console.log('ready!');
});
$(function() {
console.log('ready!');
});
function readyFn() {
// code to run when the document is ready
}
$(document).ready(readyFn);
$('#myId'); // 此 ID 在页面中必须唯一
$('div.myClass'); // 如果指定了元素类型,那么性能会有所提升
$('input[name=first_name]'); // 速度有点慢,尽量避免这种用法
$('#contents ul.people li');
$('a.external:first');
$('tr:odd');
$('#myForm :input'); // 选择表单中的所有 input 类元素
$('div:visible');
$('div:gt(2)'); // 页面中除了前 3 个 DIV 之外的所有 DIV
$('div:animated'); // 所有正在执行动画的 DIV
jQuery.expr.filters.hidden = function( elem ) {
var width = elem.offsetWidth, height = elem.offsetHeight,
skip = elem.nodeName.toLowerCase() === "tr";
// does the element have 0 height, 0 width,
// and it's not a <tr>?
return width === 0 && height === 0 && !skip ?
// then it must be hidden
true :
// but if it has width and height
// and it's not a <tr>
width > 0 && height > 0 && !skip ?
// then it must be visible
false :
// if we get here, the element has width
// and height, but it's also a <tr>,
// so check its display property to
// decide whether it's hidden
jQuery.curCSS(elem, "display") === "none";
};
jQuery.expr.filters.visible = function( elem ) {
return !jQuery.expr.filters.hidden( elem );
};
if ($('div.foo')) { ... }
if ($('div.foo').length) { ... }
var $divs = $('div');
$('div.foo').has('p'); // 所有包含有 <p> 的 div.foo
$('h1').not('.bar'); // 没有被标记 bar 这个类的 h1 元素
$('ul li').filter('.current'); // 带有类 current 的无序列表
$('ul li').first(); // 无序列表中的第一个元素
$('ul li').eq(5); // 第六个
$('#myForm :input'); // 选择所有可输入的表单元素
$('#content').find('h3').eq(2).html('new text for the third h3!');
$('#content')
.find('h3')
.eq(2)
.html('new text for the third h3!');
$('#content')
.find('h3')
.eq(2)
.html('new text for the third h3!')
.end() // 返回最初的结果集
.eq(0)
.html('new text for the first h3!');
$('h1').html('hello world'); // setter
var str = $('h1').html(); // getter
var strsize1 = $('h1').css('fontSize'); // 返回 "19px"
var strsize2 = $('h1').css('font-size'); // 同上
$('h1').css('fontSize', '100px'); // 给单个属性赋值
$('h1').css({ 'fontSize' : '100px', 'color' : 'red' }); // 给多个属性赋值
var $h1 = $('h1');
$h1.addClass('big');
$h1.removeClass('big');
$h1.toggleClass('big');
if ($h1.hasClass('big')) { ... }
$('h1').width('50px'); // 设置所有 h1 元素的宽度
$('h1').width(); // 得到第一个 h1 元素的宽度
$('h1').height('50px'); // 设置所有 h1 元素的高度
$('h1').height(); // 得到第一个 h1 元素的高度
$('h1').position(); // 返回第一个 h1 元素
// 的位置信息,此返回值是一个对象
// 此位置是相对其父元素的位置的偏移量
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有