
上QQ阅读APP看书,第一时间看更新
3.3.1 jQuery的基本选择器
jQuery的基本选择器与CSS选择器语法相同,也是通过元素标签、id、class的方式来指定页面中元素。在网页中,每个id名称只能使用一次,class允许重复使用。jQuery的基本选择器如表3.1所示。
表3.1 jQuery的基本选择器

【例3-4】 jQuery基本选择器的#id选择器应用示例。在HTML页面上有一个id属性值为test的文本框和一个按钮,通过单击按钮获取文本输入框中所输入的值。

程序运行结果如图3.4所示。

图3.4 #id选择器应用示例
【例3-5】 jQuery基本选择器的.class选择器应用示例。在HTML文档中设置一个空区域块,并由CSS设置该区域的背景颜色,通过jQuery()方法改变该区域块的背景颜色。

程序运行结果如图3.5所示。

图3.5 class选择器应用示例