Welcome

首页 / 脚本样式 / jQuery / jQuery入门[2]-选择器

jQuery入门[2]-选择器2011-11-01 cnblogs thinhunan LynjQuery之所以令人爱不释手,在于其强大的选择器表达式令DOM操作优雅而艺术。

jQuery的选择符支持id,tagName,css1-3 expressions,XPath,参见: http://docs.jquery.com/Selectors

DEMO:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Selector</title><script src="../scripts/jquery-1.2.3.intellisense.js" type="text/javascript"></script></head><body><input value="1" /> + <input value="2" /><input type="button" value="=" /><label>&nbsp;</label><script type="text/javascript">$("input[type="button"]").click(function(){var i = 0;$("input[type="text"]").each(function(){i += parseInt($(this).val());});$("label").text(i);});$("input:lt(2)").add("label").css("border","none").css("borderBottom","solid 1px navy").css({"width":"30px"});</script></body></html>
运行效果如下: