jquery特殊符号含意
jquery写作方式:
?? ? ? ? ? ? ??//完整的写法
jQuery(document).ready(function() { alert("Hello"); });
//jQuery 可简写为 $
$(document).ready(function() { alert("Hello"); });
//$(document) 可以简写为 $()
$().ready(function() { alert("Hello"); });
//$(document).ready() 也可以简写为 $()
$(function() { alert("Hello"); });
window.onload与$(function(){})区别
window.onload() 发生在页面载入完成时,
$(document).ready() 发生在页面主体框架载入完成时(或许某个图片还没下载完);
基本选择
代码:
<div id="div1">AAA</div>
<div style="line-height: 28px;">获取每小组第奇数个$("li:nth-child(odd)")//nth-child是1开始
获取每小组第几个:$("li:nth-child(2)")//nth-child是1开始的
表达式获取第几个$("li:nth-child(3n-1)")//n是从1开始的
如果是父元素中唯一的子元素 $("li:only-child")
not是取其反 ?$("li:not(li:only-child)")
根据属性来选择
代码
?
<div id="names">names</div>
<div id="hello" ?name='ss'>hello</div>
<div id="spans" ?name='spanname'><span>中国人</span></div>
<div id="worlds">worlds</div>
<div id="empty"></div>
指定元素包含id的$("div[id]")
指定元素中不包含id的$("div:not([id])")
名称为ss的元素 $("div[name='ss']")
名称不为ss的元素$("div[name!='ss']")
元素符合以world开始的$("div[id^='world']")
以o结束的$("div[id$='o']")
id 中包含ll的$("div[id*='ll']")
多个条件的,有id属性并且name中包含d的$("div[id][name*='d']")
查找内容中包括world的$("div:contains('world')")
查找包括span 的$("div:has('span')")
查找空的div ? ? $("div:empty")
查找父元素$("div:parent")
hidden和visible分别对应隐藏和显示的元素
$("div:hidden")//获取隐藏的元素
$("div:visible")//获取显示的元素
表单元素的获取
:input匹配 ?<input /> ? ? ?<select></select> ? ?<textarea></textarea> ? <button />
:text匹配<input type='text' />
:password匹配<input type='password' />
:radio 匹配<input type='radio' />
:checkbox 匹配<input type='checkbox' />
:submit 匹配<input type='submit' />
:button 匹配<input type='button' /> <button />
:reset 匹配<input type='reset' />
:image 匹配<input type='image' />
:file 匹配<input type='file' />
:enabled匹配所有可用的input
:disabled匹配所有不可用的input
:checked 匹配所有选中的单选复选按钮
:selected 匹配所有选中的option
以上的内容 是根据 http://tech.ddvip.com/2010-06/1276246634155161_4.html进行整理修改的