不通过页面提交如何实现两个复选框(multiple select)之间内容的传递??解决后马上给分!

flywolfkyo 2003-10-20 10:58:34
比如现在我有两个复选框,中间两个移动按钮(一个是“左移”,一个是“右移”)
我现在在左边的复选框中选中了两项,然后点击“右移”按钮,这两项就能添加到右边的复选框中。相反的,点“左移”的话就产生相反的操作效果。

我知道通过提交页面传递参数可以实现。
怎样才能不提交页面来实现这样的转移呢?用Javascript或者vbscript可以吗?请指点!

能实现的话马上给分!
...全文
121 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
flywolfkyo 2003-10-20
  • 打赏
  • 举报
回复
to: hover_online(ξ芎メ)
太感谢了!真想多给你几十分!可惜分不够了 :)
1蓝天1 2003-10-20
  • 打赏
  • 举报
回复
顶一下,学习
hover_online 2003-10-20
  • 打赏
  • 举报
回复
<script language="JavaScript" TYPE="text/javascript">
<!--

//Everything you see here was written by Guy Malachi guy@guymal.com

function MoveUp(combo_name)
{
var combo=document.getElementById(combo_name);
i=combo.selectedIndex;
if (i>0)
{
swap(combo,i,i-1);
combo.options[i-1].selected=true;
combo.options[i].selected=false;
}
}

function MoveDown(combo_name)
{
var combo=document.getElementById(combo_name);
i=combo.selectedIndex;

if (i<combo.length-1 && i>-1)
{
swap(combo,i+1,i);
combo.options[i+1].selected=true;
combo.options[i].selected=false;
}
}

//this function is used to swap between elements
function swap(combo,index1, index2)
{
var savedValue=combo.options[index1].value;
var savedText=combo.options[index1].text;

combo.options[index1].value=combo.options[index2].value;
combo.options[index1].text=combo.options[index2].text;

combo.options[index2].value=savedValue;
combo.options[index2].text=savedText;
}

function MoveToTop(combo_name)
{
var combo=document.getElementById(combo_name);
i=combo.selectedIndex;

for (;i>0;i--)
{
swap(combo,i,i-1);
combo.options[i-1].selected=true;
combo.options[i].selected=false;
}
}

function MoveToBottom(combo_name)
{
var combo=document.getElementById(combo_name);
i=combo.selectedIndex;

if (i>-1)
{
for (;i<combo.length-1;i++)
{
swap(combo,i+1,i);
combo.options[i+1].selected=true;
combo.options[i].selected=false;
}
}
}

//moves options from one selection box (combo box) to another
//removes the all selected options from one combo box and adds them to the second combo box
function MoveElements(FromComboName,ToComboName)
{
var FromCombo=document.getElementById(FromComboName);
var ToCombo=document.getElementById(ToComboName);

var to_remove_counter=0; //number of options that were removed (num selected options)

//move selected options to right select box (to)
for (var i=0;i<FromCombo.options.length;i++)
{
if (FromCombo.options[i].selected==true)
{
var addtext=FromCombo.options[i].text;
var addvalue=FromCombo.options[i].value;
ToCombo.options[ToCombo.options.length]=new Option(addtext,addvalue);
FromCombo.options[i].selected=false;
++to_remove_counter;
}
else
{
FromCombo.options[i-to_remove_counter].selected=false;
FromCombo.options[i-to_remove_counter].text=FromCombo.options[i].text;
FromCombo.options[i-to_remove_counter].value=FromCombo.options[i].value;
}
}

//now cleanup the last remaining options
var numToLeave=FromCombo.options.length-to_remove_counter;
for (i=FromCombo.options.length-1;i>=numToLeave;i--)
{
FromCombo.options[i]=null;
}
}

function toggleSelectAll(combo_name)
{

var select_all_link=document.getElementById('select_all_link');
var combo=document.getElementById(combo_name);//get the select

var to_select=true;
var select_link_new_caption;//the new "Select All" link caption will be here
if (select_all_link.unselectAll==true)//this is a new attribute that is dynamically added
{
//we now want to select all options
to_select=false;
select_all_link.unselectAll=false;
select_link_new_caption="Select All";//set the new caption
}
else
{
//we now want to unselect all options
select_all_link.unselectAll=true;
select_link_new_caption="Unselect All";//set the new caption
}

select_all_link.innerText=select_link_new_caption;//change the caption of the select all link
SelectAll(combo,to_select);
}

//select is true for selecting all, false for unselecting all
function SelectAll(combo,select)
{
for (var i=0;i<combo.options.length;i++)
{
combo.options[i].selected=select;
}
}
//-->
</script>

</head>
<body>
<table border=0 cellspacing=0 cellpadding=0>
<tr style='font-size: .8em;'>
<td valign=bottom align=left >
All Elements [ <span onClick='toggleSelectAll("left_select")' style='color:blue;cursor:pointer;cursor:hand;' onMouseOver='this.style.color="red"' onMouseOut='this.style.color="blue"' id='select_all_link'>Select All</span> ]
</td>
<td>
 
</td>
<td align=left valign=bottom align=right >
Selected Elements
</td>
<td>
 
</td>
</tr>
<tr valign=top>
<td rowspan=4>
<select multiple Name='left_select' id='left_select' size='10' TABINDEX=1 style='width:100%'>
<option VALUE="bill@ms.com">Bill Gates</option>
<option VALUE="bill@unemployed.com">Bill Clinton</option>
<option VALUE="bart@brat.com">Bart Simpson</option>
<option VALUE="oj@free.com">OJ Simpson</option>
<option VALUE="j@nbc.com">Jay Leno</option>
<option VALUE="david@topten.com">David Letterman</option>
<option VALUE="maybe@next-time.com">Al Gore</option>
<option VALUE="prez@whitehouse.gov">George W. Bush</option>
</select>
</td>
<td rowspan=4 valign=center>
<input title='Move elements to the right select box.' TABINDEX=2 onClick='MoveElements("left_select","right_select");' style='width:76;cursor:hand;' type=button value="Add »">
<br>
<input title='Return elements to the left select box.' TABINDEX=3 onClick='MoveElements("right_select","left_select")' style='width:76;cursor:hand;' type=button value="« Remove">
</td>
<td rowspan=4>
<select multiple Name='right_select' id='right_select' size='10' style='width:184px' TABINDEX=4 >
</select>
</td>
<td>
<input title='Move selected element to the top.' TABINDEX=5 onClick='MoveToTop("right_select")' style='width:20;height:40px;font-size:x-small;' type=button value=" /\  
 /\   ">
</td>
</tr>
<tr valign=bottom>
<td>
<input title='Move selected element up.' TABINDEX=6 onClick='MoveUp("right_select")' style='width:20px;height:20px;font-size : x-small;' type=button value="/\">
</td>
</tr>
<tr valign='top'>
<td>
<input title='Move selected element down.' TABINDEX=7 onClick='MoveDown("right_select")' style='width:20px;height:20px;font-size : x-small;' type=button value="\/">
</td>
</tr>
<tr valign='bottom'>
<td>
<input title='Move selected element to the bottom.' TABINDEX=8 onClick='MoveToBottom("right_select")' style='width:20px;height:40px;font-size : x-small;' type=button value=" \/  
 \/   ">
</td>
</tr>
</table>
<br>
<br>
<br>
<br>
<hr>
<div align='right'>?2003 guymal.com - Guy Malachi, All Rights Reserved</div>
</body>
</html>
HTML + JavaScript + Ajax + CSS 赵旭 zhaoxu@tedu.cn HTML5 1、WEB基础知识(了解) 1、Internet - 网 由若干台电脑、手机、平板 通过 网线(WIFI) 连接起来的结构 2、基于Internet上的程序 1、C / S 结构 Client / Server 特点:必须通过指定的客户端软件才能访问服务器端的一种程序 :如 :桌面版QQ,... ... 2、B / S 结构 Browser / Server Browser :浏览器 特点:通过 浏览器 就能访问服务器端的一种程序 如 :网页版百度,网页版 QQ,网页版 京东,... ... 3、WEB 1、什么是WEB WEB,是基于Internet上的一种应用程序(网页应用程序) WEB页面,简称WEB页(网页),就是保存在服务器端上的一个具体的页面( **.html / **.htm 作为结尾的文件) 2、WEB浏览器 1、功能 1、提交用户请求 (UA : User Agent) 2、作为HTML 以及 脚本执行的 解释器 3、以图形化的方式显示web页面 2、主要浏览器产品 1、Microsoft Internet Explorer (IE) 2、Mozilla Firefox 3、Google Chrome 4、Apple Safari 5、Opera Opera(欧朋) 3、主要技术 1、HTML 2、CSS 3、Javascript 2、HTML入门(重点) 1、什么是HTML Hyper Text Markup Language 超级 文本 标记 语言 超文本 :也是文本,但会具备特殊功能 普通文本 a : 普通字符 a 超文本 a : 表示超链接 普通文本 b : 普通字符 b 超文本 b : 加粗显示文本 标记 :超文本的表现形式 普通文本 a : a 超文本 a : 语言 :具备一定的语法规范 HTML 也具备自己的语法规范 WEB页面(HTML页面)就是由 HTML 语言来进行开发的 ,以 .html 或 .htm 进行结尾的文件 开发 & 运行网页的工具: 1、记事本 2、浏览器 2、HTML 的基础语法 1、标记语法 HTML中用于描述功能的符号称为"标记" 标记在使用时,用尖括号 "",标记的类 1、封闭类型的标记 也称为 "双标记" , 必须成对出现 语法:内容 Demo : 1、创建 p 标记 --... 2、创建 div 标记 -- 3、创建 header 标记 -- <header></header> 2、非封闭类型的标记 也称为 "单标记" 语法: 或 Demo : 1、创建 br 标记 -- 2、创建 hr 标记 -- 3、创建 img 标记 -- 4、创建 input 标记 -- <input/> 2、标记(元素)的嵌套 在一对标记中,允许出现另外一对(一个)标记 注意:嵌套标记的书写格式 -- 被嵌套的标记要通过一个 缩进键(Tab) 来表示层级关系 Demo : 1、编写一对 body 标记,在body标记中,嵌套一对 div标记,在 div 标记中 ,嵌套一对 a 标记,在 a标记中,嵌套一对 b 标记,b标记中,随意编写一些文本 <body> 这是一段测试文本 </body> 3、标记的属性 1、什么是属性 用来修饰标记的效果的内容,就是属性 2、语法 1、属性必须声明在开始标记中 2、属性与标记名称之间,用 空格 隔开 3、属性的值 与 属性之间 使用 "=" 连接 4、一个元素允许有多属性,多属性间,排名不先后,中间用 空格 隔开即可 Demo : 1、创建一个 div 标记 ,增加属性 ,设置 align 属性的值为 center ,设置 id 属性的值为 container,设置 title 属性的值为 这是一个div 四大标准属性: 1、id :定义元素在页面中独一无二的名称 2、title :鼠标悬停在元素上时,体现的文字 3、class :引用 类选择器时使用(CSS中) 4、style :定义 内联方式方式使用(CSS中) 4、注释 语法:<!-- --> 注意: 1、注释不能嵌套 2、注释不能出现在标记中 3、HTML 文档结构 W3C :Word Wide Web Consortium (万维网联盟) 1、HTML文档的组成 1、文档类型声明 告知浏览器当前的HTML文档用的是哪个版本 在网页的最顶端 2、由一对 html 根标记,来表示页面的开始与结束 Demo : 1、在 htdoc 中,创建一个网页 01-first.html 文件 创建一个 记事本,将 .txt 重命名为 .html 2、搭建HTML网页结构 1、添加 文档类型声明 2、添加 html 根标记 2、<html> 标记 包含两对子元素 1、<head></head> 包含的子元素(2对) 1、<title>网页的标题</title> 2、<meta charset="utf-8"/> -- 能正常显示中文 2、<body></body> 属性: 1、text ,取值是一个颜色值(red,green,blue...) 2、bgcolor ,取值也是一个颜色值 Demo : 在刚才的 Demo 基础上 1、在 <html>中 增加 <head> 和 <body> 2、为网页指定标题 - 我的第一个HTML文档 3、指定网页的字符编码格式为 utf-8 4、在 body 中 输出一句话 "我的第一HTML页面" 5、设置 body text为red,bgcolor为yellow 3、文本 1、特殊文本的实现 页面的空格以及一些特殊字符需要通过转义字符的方式体现 1、  表示一个空格 2、< 表示 4、© 表示© Demo : 1、创建一个页面 02-text.html 2、在页面中 输出以下内容 The element. ©2017 By Tarena The <p> element.     © By Tarena 2、文本样式相关标记 : 加粗 : 斜体 : 下划线 : 删除线 : 上标 : 下标 Demo : 这是一段包含 ,粗体,斜体,下划线,删除线,上标,下标的文本内容 将以上文本内,对应文字的特殊效果,用标记体现出来 3、标题元素 以 醒目 的方式表现出文本 语法: 一级标题 二级标题 三级标题 四级标题 五级标题 六级标题 属性: 1、align 文本的水平对齐方式 取值:left / center / right 4、段落元素 语法: 属性:align : left / center / right Demo : 1、在 02-text.html 中,增加以下内容 1、用 段落标记表示 :The first paragraph 2、用 段落标记表示 :The second paragraph ,文本表现为 右对齐 5、换行元素 6、割线元素 作用:在页面中表现为一条直线 语法: 属性: 1、size 尺寸,以 px 为单位的数值 2、width 宽度,以 px 或 % 为单位的数值 3、align 水平对其方式 4、color 颜色 Demo : 02-text.html 中 增加一根水平线,size为5px,宽度为50%,居中对齐,颜色为红色(red) 7、预格式化 作用:保留源文档中的回车 和 空格 的作用 8、区元素 1、块区元素 语法: 作用:布局 2、行内区元素 语法: 作用:设置同一行文字内的不同样式 9、行内元素 与 块级元素 按照元素们的表现形式来类,为 行内元素 和 块级元素1、行内元素 在一行内允许显示多个元素的,称为 "行内元素" span,i,b,s,u,sup,sub 作用:包裹文本,并处理文本的表现形式 2、块级元素 每个元素独占一行显示的,称为 "块级元素" div,p,h1,h2,h3,h4,h5,h6 作用:布局 注意: 1、p标记不能嵌套其它的块级元素 2、行内元素中 最好 不要嵌套块级元素 4、图像 和 链接 1、URL 目录结构 : 目录 ,保存文件的文件夹名称 多个文件夹之间的关系,就是目录结构 1、什么是 URL URL (Uniform Resource Locator),统一资源定位器。用来标识某资源文件的位置 2、URL 在 WEB 中的表现形式 共三种表现形式: 1、绝对路径 特点:从文件所在的最高级目录处开始查找资源文件所经过的路径,就是绝对路径 使用场合:当想访问互联网上的资源时,只能用绝对路径 完整的绝对路径四部: 1、协议名 http 2、域名(主机名,IP地址) www.codeboy.com 3、目录路径 img/header 4、文件名 logo.png http://www.codeboy.com/img/header/logo.png img/header/logo.png 2、相对路径(重点) 场合:使用本机文件时使用 什么是相对路径: 从当前文件位置处开始查找资源文件所经过的路径,就是相对路径 1、同目录,直接用 2、子目录,先进入 3、父目录,先返回 3、根相对路径 路径形式是以 / 作为开始的。 / : 表示的是服务器的根路径 2、图像 1、图像格式 WEB中支持的图像格式 1、*.jpg 2、*.gif(动图) 3、*.png(透明) 2、图像的语法 标记: 属性: 1、src :指定要显示图像的 URL 2、width :图像的宽度 3、height :图像的高度 4、title :鼠标悬停时,要显示的文本 Demo : 1、将 学子网的 logo 下载下来 2、显示在自己的网页中 3、超链接 1、语法 标记:内容 属性: 1、href : 要链接的HTML页面URL 2、target : 目标,指定新网页的打开形式 取值: 1、_blank : 在新标签页中打开网页 2、_self : 在自身标签页中打开新网页(默认值) Demo 1、创建一个超链接,内容为 :学子商城,点击时,在自身标签页中 打开 http://www.codeboy.com 2、创建一个超链接,内容为 :学子商城的LOGO,点击时,在新标签页中打开 http://www.codeboy.com 2、链接的四种表现形式 1、点击操作时,完成资源下载的操作 链接的资源为 zip / rar 时则为下载操作 下载 2、电子邮件链接 联系我们 前提 : 必须在计算机中安装并配置好至少一个邮件客户端的信息 3、返回页面顶部的空连接 返回顶部 4、执行Javascript代码片段 执行JS 3、锚点 1、作用 锚点用于在网页中的某个位置处做个记号,允许从其他位置处跳转到记号位置处 2、使用方式 1、定义锚点 1、使用 a 标记的 name 属性允许定义锚点 xxxx 2、任何标记的 id 属性定义锚点 2、链接到锚点 链接到锚点 链接到锚点 5、表格 1、表格 1、表格的作用 按照一定的格式来显示数据的 表格是由 单元格(列),行 来组成的 2、表格的语法 1、标记 1、 : 表示一个表格 2、 : 表示表格中的一行 3、 : 表行中的一列(单元格) : 行/列 标题 (加粗,水平居中) 4、 : 表格的标题 该元素必须添加在 之下,所有的tr之上 2、常用属性 1、table 1、width 2、height 3、align 设置表格的对齐方式 , left / center / right 4、border 边框宽度,取值以 px 为单位的数值 5、bgcolor 6、cellspacing :单元格外边距(单元格与单元格 或 单元格与表格之间的距离) 7、cellpadding : 单元格内边距(单元格与内容之间的距离) 2、tr 1、align 控制当前行内容的水平对齐方式 2、valign 控制当前行内容的垂直对齐方式 top / middle / bottom 3、bgcolor 3、td / th 1、align 2、valign 3、width 4、height 5、colspan :跨列 6、rowspan :跨行 Demo : 在 刚才的表格基础上,增加以下内容 1、为表格增加边框 1px 2、为表格增加尺寸 400 * 400 3、为表格增加单元格内边距 5px 4、为第四行 增加属性 ,内容水平居中对齐 3、表格的复杂应用 1、行组 允许将若干行划到一个组中,以便实现统一管理 1、表头行组 允许将第一行的内容单独到表头行组中 2、表尾行组 允许将最后一行的内容单独到表尾行组中 3、表主体行组 2、不规则表格创建 通过 td 的跨行 和 跨列来实现不规则的表格 1、跨列 从指定单元格位置处开始,横向向右,合并掉几个单元格(包含自己),被合并掉的单元格,要删除 2、跨行 从指定单元格位置处开始,纵向向下,合并掉几个单元格(包含自己),被合并掉的单元格,要删除 3、表格的嵌套 被嵌套的所有的内容,只能放在 td 中 2、列表 1、作用 按照一定的格式显示数据 2、列表的类 & 语法 1、列表的组成 由列表类型 以及 列表项 来组成 2、类 & 语法 1、有序列表 --> Order List 允许包含若干列表项: --> List Item 2、无序列表 --> Unorder List 允许包含若干列表项: 3、属性 1、ol 1、type 1 、按数字方式排列,默认值 a 、按小写英文方式排列 A 、按大写英文方式排列 i 、按小写罗马数字排列 I 、按大写罗马数字排列 2、start 指定标识从 几 开始显示 2、ul 1、type 1、disc,实心圆,默认值 2、circle,空心圆 3、square,实心矩形 4、none 3、列表的嵌套 被嵌套的内容只能放在 li 中 Demo : 1、声明一个列表在 html 中(有序),包含两个列表项,显示 两部小说的名字 2、在两个列表项中,再各嵌套一个无序列表,各写3-4个小说中的主角 3、定义列表 1、作用 以一种特殊的结构来排列数据 通常用语对一类事物/名词 的解释上面 2、语法 :声明一个定义列表 :声明要解释的事物名称 或 名词 :对上述名词或事物解释的内容 3、常用场合 图文混排 3、结构标记 1、结构标记的作用 搭建网页的结构(布局),用于替代 div,最大的优点是提升了标记的"语义性" 2、结构标记详解 1、<header></header> 作用:表示网页 或 某块内容的头部 2、 作用:表示网页中的 导航内容 3、 作用:表示网页主体内容中的某一部 4、 作用:出现在文字描述性比较强的场合:一则新闻,论坛中的帖子,微博信息,博客的信息 5、 作用:表示网页中,或某部内容的 边栏信息 6、 作用:表示网页中尾部的信息 4、表单(难点) 1、表单的作用 用于收集用户的信息并提交给服务器 表单主体是由两部组成的 1、表单元素 收集信息,并提交给服务器 2、表单控件 用于与用户交互的一些元素:文本框,密码框 2、表单元素(难点) 标记:<form></form> 注意:只有放在 <form></form> 里面的表单控件的值,才能提交给服务器 属性: 1、action 提交给服务器处理程序的地址 (动作) 2、method 提交方式,以什么样的方式把数据交给服务器 1、get 特点: 1、以明文的方式将数据传递给服务器(提交的数据会显示在地址栏上) 2、安全性很低 3、提交数据最大限制为 2KB 4、向服务器要数据时可以使用 2、post 特点: 1、以隐式的方式将数据传递给服务器 2、安全性很高 3、不限制提交数据的大小 4、要提交数据给服务器处理时使用 3、... ... 3、enctype 作用:指定表单数据进行编码的方式 取值: 1、application/x-www-form-urlencoded 默认值,允许将任意类型的文本提交给服务器 2、multipart/form-data 允许将文件提交给服务器 3、text/plain 不对任何数据进行编码和传输 Demo : 1、创建 05-form.html 2、声明一个表单元素 form 3、指定提交地址为 login.php,提交方式为 get,编码方式为默认 3、表单控件 表单元素类: 1、input元素 2、textarea 多行文本域 3、select 和 option 选项框 4、其它元素 5、新input元素 详解 : 1、input元素 里面会包含若干个不同的表单控件 标记 :<input> 属性 : 1、type 根据不同的type属性值,可以创建不同的input元素 2、name 定义表单控件的名称,主要提交给服务器使用的 注意:如果不声明name属性的话,元素则无法提交给服务器 3、value 定义当前控件的值,主要提交给服务器使用的 4、disabled 禁用控件,无值的属性 <input disabled> 2、文本框 与 密码框 文本框:<input type="text"> 密码框:<input type="password"> 具备除以上四个属性外,还具备以下几个独立属性: 1、maxlength 限制输入的字符数,取值为数字 2、readonly 只读,无值属性 Q : readonly 和 disabled 的区别 1、readonly ,是只读的意思,是允许提交给服务器,不让用户改数据而已 2、disabled , 是禁用的意思,不仅不让用户改数据,而且还不能提交给服务器 3、placeholder 占位符,即默认显示在文本框用于给用户提示的文字 3、按钮 1、提交按钮 作用:将表单提交给服务器 标记:<input type="submit" value="显示的文本"> 2、重置按钮 作用:将表单恢复到初始化的状态 标记:<input type="reset" value="显示的文本"> 3、普通按钮 作用:通过 JS 自定义功能 标记:<input type="button" value="显示的文本"> 4、显示的内容 属性: 1、type :submit / reset / button 4、单选按钮 和 复选框 单选按钮:<input type="radio"> 复选框:<input type="checkbox"> 属性: 1、name 设置名称,并用于组,一组单选按钮 或 复选框的名称必须相同 2、value 必须设置 3、checked 默认被选中,无值属性 5、隐藏域 和 文件选择框 1、隐藏域 <input type="hidden" name="" value=""> 想提交给服务器,但不想给用户看的数据,可以放在隐藏域中 2、文件选择框 <input type="file" name=""> 注意: 1、form的 method 属性值必须为 post 2、form的 enctype属性值必须为 multipart/form-data http://localhost/02-HTML/Day02/login.php?uname=wenhua.li&upwd=bingbing http://localhost/02-HTML/Day02/login.php?uname=wenhua.li&upwd=fengjie&gender=1&question=0&question=1&question=2&question=3 http://localhost/02-HTML/Day02/login.php?uname=wenhua.li&upwd=fdsafdsafdsa&gender=0&question=0&question=1&question=2&question=3&uid=10000567789 1、表单 1、form ... 2、input ... 3、textarea 控件 标记:<textarea></textarea> 属性: 1、name 定义名称,提交给服务器使用 2、cols 指定文本域的列数,变相指定宽 3、rows 指定文本域的行数,变相指定高 4、readonly 只读 Demo : 创建 01-form.html 文件 创建一个 多行文本域,列数为 50,行数为 5,名称为 intro 4、选项框 1、标记 表示 下拉列表 或 滚动列表 列表中的内容,允许出现多个 2、属性 1、 1、name :控件的名称 2、size :默认显示选项的数量,默认为1,为下拉列表,如果取值>1的话,则为滚动列表 3、multiple 设置多选,无值的属性 2、 1、value :选项的值,提交给服务器用 2、selected :默认被选中 5、其它标记 1、label 元素 作用:关联文本与表单控件的,点击文本时就如同点击表单控件一样 标记:文本 属性: 1、for 指定要关联的表单控件的ID值 2、为控件组标题 组中的内容 3、浮动框架 1、作用 将其他页面导入到当前页面中来 2、语法 标记:<iframe></iframe> 属性: 1、src 要引入的页面的url 2、frameborder 指定浮动框架的边框,默认为1,则显示边框 不需要边框则设置为 0 3、width 4、height 练习: 创建一个 02-iframe 的网页,将 01-form.html 页面引入进来 ,适当调整宽度,高度,边框 6、新input元素 (HTML5) 1、电子邮件类型 作用:提交时会验证数据是否符合Email的规范 标记:<input type="email"> 2、搜索类型 作用:在文本框的基础上,提供了快速清除操作 标记:<input type="search"> 3、URL类型 作用:提交时会验证数据是否符合Web站点的URL规范(绝对路径) 标记:<input type="url"> 4、电话号码类型 作用:在移动端设备中,能展开 拨号键盘,在PC中无效 标记:<input type="tel"> 5、数字类型 作用:只能让用户输入 或 选择数字 标记:<input type="number"> 属性: 1、min :当前控件接受的最小值 2、max :当前控件接受的最大值 3、step :微调数字时每次变化的长度,默认为1 6、范围类型 作用:提供一个滑块,让用户选择数字 标记:<input type="range"> 属性: 1、min :当前控件的最小值 2、max :当前控件的最大值 3、value :设定初始值 7、颜色类型 作用:提供一个颜色拾取控件 语法:<input type="color"> 8、日期类型 作用:提供一个日期输入控件 标记:<input type="date"> 9、周类型 作用:提供一个日期控件,用于选取周 标记:<input type="week"> 10、月份类型 作用:选取月份控件 标记:<input type="month"> =============================
jQuery1.2 API 中文版折叠展开折叠全部展开全部 英文说明 核心jQuery 核心函数 jQuery(expression,[context]) jQuery(expression,[context]) 这个函数接收一个包含 CSS 选择器的字符串,然后用这个字符串去匹配一组元素。 jQuery 的核心功能都是通过这个函数实现的。 jQuery中的一切都构建于这个函数之上,或者说都是在以某种方式使用这个函数。这个函数最基本的用法就是向它传递一个表达式(通常由 CSS 选择器组成),然后根据这个表达式来查找所有匹配的元素。 默认情况下, 如果没有指定context参数,$()将在当前的 HTML 文档中查找 DOM 元素;如果指定了 context 参数,如一个 DOM 元素集或 jQuery 对象,那就会在这个 context 中查找。 参考 Selectors 获取更多用于 expression 参数的 CSS 语法的信息。 -------------------------------------------------------------------------------- This function accepts a string containing a CSS selector which is then used to match a set of elements. The core functionality of jQuery centers around this function. Everything in jQuery is based upon this, or uses this in some way. The most basic use of this function is to pass in an expression (usually consisting of CSS), which then finds all matching elements. By default, if no context is specified, $() looks for DOM elements within the context of the current HTML document. If you do specify a context, such as a DOM element or jQuery object, the expression will be matched against the contents of that context. See Selectors for the allowed CSS syntax for expressions. 返回值 jQuery 参数 expression (String) : 用来查找的字符串 context (Element, jQuery) : (可选) 作为待查找的 DOM 元素集、文档或 jQuery 对象。 示例 找到所有 p 元素,并且这些元素都必须是 div 元素的子元素。 HTML 代码:

one

two

three

jQuery 代码: $("div > p"); 结果: [

two

] -------------------------------------------------------------------------------- 在文档的第一个表单中,查找所有的单选按钮(即: type 值为 radio 的 input 元素)。 jQuery 代码: $("input:radio", document.forms[0]); -------------------------------------------------------------------------------- 在一个由 AJAX 返回的 XML 文档中,查找所有的 div 元素。 jQuery 代码: $("div", xml.responseXML); jQuery(html)jQuery(html) 根据提供的原始 HTML 标记字符串,动态创建由 jQuery 对象包装的 DOM 元素。 你可以传递一个手写的 HTML 字符串,或者由某些模板引擎或插件创建的字符串,也可以是通过 AJAX 加载过来的字符串。但是在你创建 input 元素的时会有限制,可以参考第二个示例。当然这个字符串可以包含斜杠 (比如一个图像地址),还有反斜杠。当你创建单个元素时,请使用闭合标签或 XHTML 格式。例如,创建一个 span ,可以用 $("") 或 $("") ,但不推荐 $("") -------------------------------------------------------------------------------- Create DOM elements on-the-fly from the provided String of raw HTML. You can pass in plain HTML Strings written by hand, create them using some template engine or plugin, or load them via AJAX. There are limitations when creating input elements, see the second example. Also when passing strings that may include slashes (such as an image path), escape the slashes. When creating single elements use the closing tag or XHTML format. For example, to create a span use $("") or $("") instead of without the closing slash/tag. 返回值 jQuery 参数 html (String) : 用于动态创建DOM元素的HTML标记字符串 示例 动态创建一个 div 元素(以及其中的所有内容),并将它追加到 body 元素中。在这个函数的内部,是通过临时创建一个元素,并将这个元素的 innerHTML 属性设置为给定的标记字符串,来实现标记到 DOM 元素转换的。所以,这个函数既有灵活性,也有局限性。 jQuery 代码: $("

Hello

").appendTo("body"); -------------------------------------------------------------------------------- 创建一个 元素必须同时设定 type 属性。因为微软规定 元素的 type 只能写一次。 jQuery 代码: // 在 IE 中无效: $("").attr("type", "checkbox"); // 在 IE 中有效: $(""); jQuery(elements)jQuery(elements) 将一个或多个DOM元素转化为jQuery对象。 这个函数也可以接收XML文档和Window对象(虽然它们不是DOM元素)作为有效的参数。 -------------------------------------------------------------------------------- Wrap jQuery functionality around a single or multiple DOM Element(s). This function also accepts XML Documents and Window objects as valid arguments (even though they are not DOM Elements). 返回值 jQuery 参数 elements (Element, Array) : 用于封装成jQuery对象的DOM元素 示例 设置页面背景色。 jQuery 代码: $(document.body).css( "background", "black" ); -------------------------------------------------------------------------------- 隐藏一个表单中所有元素。 jQuery 代码: $(myForm.elements).hide() jQuery(callback)jQuery(callback) $(document).ready()的简写。 允许你绑定一个在DOM文档载入完成后执行的函数。这个函数的作用如同$(document).ready()一样,只不过用这个函数时,需要把页面中所有需要在 DOM 加载完成时执行的$()操作符都包装到其中来。从技术上来说,这个函数是可链接的--但真正以这种方式链接的情况并不多。 你可以在一个页面中使用任意多个$(document).ready事件。 参考 ready(Function) 获取更多 ready 事件的信息。 -------------------------------------------------------------------------------- A shorthand for $(document).ready(). Allows you to bind a function to be executed when the DOM document has finished loading. This function behaves just like $(document).ready(), in that it should be used to wrap other $() operations on your page that depend on the DOM being ready to be operated on. While this function is, technically, chainable - there really isn't much use for chaining against it. You can have as many $(document).ready events on your page as you like. See ready(Function) for details about the ready event. 返回值 jQuery 参数 callback (Function) : 当DOM加载完成后要执行的函数 示例 当DOM加载完成后,执行其中的函数。 jQuery 代码: $(function(){ // Document is ready }); -------------------------------------------------------------------------------- Uses both the shortcut for $(document).ready() and the argument to write failsafe jQuery code using the $ alias, without relying on the global alias. jQuery 代码: jQuery(function($) { // Your code using failsafe $ alias here... }); jQuery 对象访问 each(callback)each(callback) 以每一个匹配的元素作为上下文来执行一个函数。 意味着,每次执行传递进来的函数时,函数中的this关键字都指向一个不同的DOM元素(每次都是一个不同的匹配元素)。 而且,在每次执行函数时,都会给函数传递一个表示作为执行环境的元素在匹配的元素集合中所处位置的数字值作为参数(从零开始的整形)。 返回 'false' 将停止循环 (就像在普通的循环中使用 'break')。返回 'true' 跳至下一个循环(就像在普通的循环中使用'continue')。 -------------------------------------------------------------------------------- Execute a function within the context of every matched element. This means that every time the passed-in function is executed (which is once for every element matched) the 'this' keyword points to the specific DOM element. Additionally, the function, when executed, is passed a single argument representing the position of the element in the matched set (integer, zero-index). Returning 'false' from within the each function completely stops the loop through all of the elements (this is like using a 'break' with a normal loop). Returning 'true' from within the loop skips to the next iteration (this is like using a 'continue' with a normal loop). 返回值 jQuery 参数 callback (Function) : 对于每个匹配的元素所要执行的函数 示例 迭代两个图像,并设置它们的 src 属性。注意:此处 this 指代的是 DOM 对象而非 jQuery 对象。 HTML 代码: jQuery 代码: $("img").each(function(i){ this.src = "test" + i + ".jpg"; }); 结果: [ , ] -------------------------------------------------------------------------------- 如果你想得到 jQuery对象,可以使用 $(this) 函数。 jQuery 代码: $("img").each(function(){ $(this).toggleClass("example"); }); -------------------------------------------------------------------------------- 你可以使用 'return' 来提前跳出 each() 循环。 HTML 代码:
Stop here
jQuery 代码: $("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; } }); });size()size() jQuery 对象中元素的个数。 这个函数的返回值与 jQuery 对象的'length' 属性一致。 -------------------------------------------------------------------------------- The number of elements in the jQuery object. This returns the same number as the 'length' property of the jQuery object. 返回值 Number 示例 计算文档中所有图片数量 HTML 代码: jQuery 代码: $("img").size(); 结果: 2 lengthlength jQuery 对象中元素的个数。 当前匹配的元素个数。 size 将返回相同的值。 -------------------------------------------------------------------------------- The number of elements in the jQuery object. The number of elements currently matched. The size function will return the same value. 返回值 Number 示例 计算文档中所有图片数量 HTML 代码: jQuery 代码: $("img").length; 结果: 2 get()get() 取得所有匹配的 DOM 元素集合。 这是取得所有匹配元素的一种向后兼容的方式(不同于jQuery对象,而实际上是元素数组)。 如果你想要直接操作 DOM 对象而不是 jQuery 对象,这个函数非常有用。 -------------------------------------------------------------------------------- Access all matched DOM elements. This serves as a backwards-compatible way of accessing all matched elements (other than the jQuery object itself, which is, in fact, an array of elements). It is useful if you need to operate on the DOM elements themselves instead of using built-in jQuery functions. 返回值 Array 示例 选择文档中所有图像作为元素数组,并用数组内建的 reverse 方法将数组反向。 HTML 代码: jQuery 代码: $("img").get().reverse(); 结果: [ ] get(index)get(index) 取得其中一个匹配的元素。 num表示取得第几个匹配的元素。 这能够让你选择一个实际的DOM 元素并且对他直接操作,而不是通过 jQuery 函数。$(this).get(0)与$(this)[0]等价。 -------------------------------------------------------------------------------- Access a single matched DOM element at a specified index in the matched set. This allows you to extract the actual DOM element and operate on it directly without necessarily using jQuery functionality on it. This function called as $(this).get(0) is the equivalent of using square bracket notation on the jQuery object itself like $(this)[0]. 返回值 Element 参数 index (Number) :取得第 index 个位置上的元素 示例 HTML 代码: jQuery 代码: $("img").get(0); 结果: [ ] index(subject)index(subject) 搜索与参数表示的对象匹配的元素,并返回相应元素的索引值值。 如果找到了匹配的元素,从0开始返回;如果没有找到匹配的元素,返回-1。 -------------------------------------------------------------------------------- Searches every matched element for the object and returns the index of the element, if found, starting with zero. Returns -1 if the object wasn't found. 返回值 Number 参数 subject (Element) : 要搜索的对象 示例 返回ID值为foobar的元素的索引值值。 HTML 代码:
jQuery 代码: $("*").index($('#foobar')[0]) 结果: 5 插件机制 jQuery.fn.extend(object)jQuery.fn.extend(object) 扩展 jQuery 元素集来提供新的方法(通常用来制作插件)。 查看这里Plugins/Authoring可以获取更多信息。 -------------------------------------------------------------------------------- Extends the jQuery element set to provide new methods (used to make a typical jQuery plugin). Can be used to add functions into the to add plugin methods (plugins). 返回值 jQuery 参数 object (Object) :用来扩充 jQuery 对象。 示例 增加两个插件方法。 jQuery 代码: jQuery.fn.extend({ check: function() { return this.each(function() { this.checked = true; }); }, uncheck: function() { return this.each(function() { this.checked = false; }); } }); 结果: $("input[@type=checkbox]").check(); $("input[@type=radio]").uncheck(); jQuery.extend(object)jQuery.extend(object) 扩展jQuery对象本身。 用来在jQuery命名空间上增加新函数。 查看 'jQuery.fn.extend' 获取更多添加插件的信息。 -------------------------------------------------------------------------------- Extends the jQuery object itself. Can be used to add functions into the jQuery namespace. See 'jQuery.fn.extend' for more information on using this method to add Plugins. 返回值 jQuery 参数 object (Object) : 用以扩展 jQuery 对象 示例 在jQuery命名空间上增加两个函数。 jQuery 代码: jQuery.extend({ min: function(a, b) { return a < b ? a : b; }, max: function(a, b) { return a > b ? a : b; } }); 结果: jQuery.min(2,3); // => 2 jQuery.max(4,5); // => 5 多库共存 jQuery.noConflict()jQuery.noConflict() 运行这个函数将变量$的控制权让渡给第一个实现它的那个库。 这有助于确保jQuery不会与其他库的$对象发生冲突。在运行这个函数后,就只能使用jQuery变量访问jQuery对象。例如,在要用到$("div p")的地方,就必须换成jQuery("div p")。 -------------------------------------------------------------------------------- Run this function to give control of the $ variable back to whichever library first implemented it. This helps to make sure that jQuery doesn't conflict with the $ object of other libraries. By using this function, you will only be able to access jQuery using the 'jQuery' variable. For example, where you used to do $("div p"), you now must do jQuery("div p"). 返回值 jQuery 示例 将$引用的对象映射回原始的对象。 jQuery 代码: jQuery.noConflict(); // 使用 jQuery jQuery("div p").hide(); // 使用其他库的 $() $("content").style.display = 'none'; -------------------------------------------------------------------------------- 恢复使用别名$,然后创建并执行一个函数,在这个函数的作用域中仍然将$作为jQuery的别名来使用。在这个函数中,原来的$对象是无效的。这个函数对于大多数不依赖于其他库的插件都十有效。 jQuery 代码: jQuery.noConflict(); (function($) { $(function() { // 使用 $ 作为 jQuery 别名的代码 }); })(jQuery); // 其他用 $ 作为别名的库的代码 -------------------------------------------------------------------------------- 创建一个新的别名用以在接下来的库中使用jQuery对象。 jQuery 代码: var j = jQuery.noConflict(); // 基于 jQuery 的代码 j("div p").hide(); // 基于其他库的 $() 代码 $("content").style.display = 'none'; jQuery.noConflict(extreme)jQuery.noConflict(extreme) 将$和jQuery的控制权都交还给原来的库。用之前请考虑清楚! 这是相对于简单的 noConflict 方法更极端的版本,因为这将完全重新定义jQuery。这通常用于一种极端的情况,比如你想要将jQuery嵌入一个高度冲突的环境。注意:调用此方法后极有可能导致插件失效。 -------------------------------------------------------------------------------- Revert control of both the $ and jQuery variables to their original owners. Use with discretion. This is a more-extreme version of the simple noConflict method, as this one will completely undo what jQuery has introduced. This is to be used in an extreme case where you'd like to embed jQuery into a high-conflict environment. NOTE: It's very likely that plugins won't work after this particular method has been called. 返回值 jQuery 参数 extreme (Boolean) : 传入 true 来允许彻底将jQuery变量还原 示例 完全将 jQuery 移到一个新的命名空间。 jQuery 代码: var dom = {}; dom.query = jQuery.noConflict(true); 结果: // 新 jQuery 的代码 dom.query("div p").hide(); // 另一个库 $() 的代码 $("content").style.display = 'none'; // 另一个版本 jQuery 的代码 jQuery("div > p").hide(); 选择器基本 #id#id 根据给定的ID匹配一个元素。 -------------------------------------------------------------------------------- Matches a single element with the given id attribute. 返回值 Element 参数 id (String) : 用于搜索的,通过元素的 id 属性中给定的值 示例 查找 ID 为"myDiv"的元素。 HTML 代码:

id="notMe"

id="myDiv"
jQuery 代码: $("#myDiv"); 结果: [
id="myDiv"
] elementelement 根据给定的元素名匹配所有元素 -------------------------------------------------------------------------------- Matches all elements with the given name. 返回值 Array 参数 element (String) : 一个用于搜索的元素。指向 DOM 节点的标签名。 示例 查找一个 DIV 元素。 HTML 代码:
DIV1
DIV2
SPAN jQuery 代码: $("div"); 结果: [
DIV1
,
DIV2
] .class.class 根据给定的类匹配元素。 -------------------------------------------------------------------------------- Matches all elements with the given class. 返回值 Array 参数 class (String) : 一个用以搜索的类。一个元素可以有多个类,只要有一个符合就能被匹配到。 示例 查找所有类是 "myClass" 的元素. HTML 代码:
div class="notMe"
div class="myClass"
span class="myClass" jQuery 代码: $(".myClass"); 结果: [
div class="myClass"
, span class="myClass" ] ** 匹配所有元素 多用于结合上下文来搜索。 -------------------------------------------------------------------------------- Matches all elements. Most useful when combined with a context to search in. 返回值 Array 示例 找到每一个元素 HTML 代码:
DIV
SPAN

P

jQuery 代码: $("*") 结果: [
DIV
, SPAN,

P

] selector1,selector2,selectorNselector1,selector2,selectorN 将每一个选择器匹配到的元素合并后一起返回。 你可以指定任意多个选择器,并将匹配到的元素合并到一个结果内。 -------------------------------------------------------------------------------- Matches the combined results of all the specified selectors. You can specify any number of selectors to combine into a single result. 返回值 Array 参数 selector1 (Selector) : 一个有效的选择器 selector2 (Selector) : 另一个有效的选择器 selectorN (Selector) : (可选) 任意多个有效选择器 示例 找到匹配任意一个类的元素。 HTML 代码:
div

p class="myClass"

span

p class="notMyClass"

jQuery 代码: $("div,span,p.myClass") 结果: [
div
,

p class="myClass"

, span ] 层级 ancestor descendantancestor descendant 在给定的祖先元素下匹配所有的后代元素 -------------------------------------------------------------------------------- Matches all descendant elements specified by descendant of elements specified by ancestor. 返回值 Array 参数 ancestor (Selector) : 任何有效选择器 descendant (Selector) : 用以匹配元素的选择器,并且它是第一个选择器的后代元素 示例 找到表单中所有的 input 元素 HTML 代码:
jQuery 代码: $("form input") 结果: [ , ] parent > childparent > child 在给定的父元素下匹配所有的子元素 -------------------------------------------------------------------------------- Matches all child elements specified by child of elements specified by parent. 返回值 Array 参数 parent (Selector) : 任何有效选择器 child (Selector) : 用以匹配元素的选择器,并且它是第一个选择器的子元素 示例 匹配表单中所有的子级input元素。 HTML 代码:
jQuery 代码: $("form > input") 结果: [ ] prev + nextprev + next 匹配所有紧接在 prev 元素后的 next 元素 -------------------------------------------------------------------------------- Matches all next elements specified by next that are next to elements specified by prev. 返回值 Array 参数 prev (Selector) : 任何有效选择器 next (Selector) :一个有效选择器并且紧接着第一个选择器 示例 匹配所有跟在 label 后面的 input 元素 HTML 代码:
jQuery 代码: $("label + input") 结果: [ , ] prev ~ siblingsprev ~ siblings 匹配 prev 元素之后的所有 siblings 元素 -------------------------------------------------------------------------------- Matches all sibling elements after the "prev" element that match the filtering "siblings" selector. 返回值 Array 参数 prev (Selector) : 任何有效选择器 siblings (Selector) : 一个选择器,并且它作为第一个选择器的同辈 示例 找到所有与表单同辈的 input 元素 HTML 代码:
jQuery 代码: $("form ~ input") 结果: [ ] 简单 :first:first 匹配找到的第一个元素 -------------------------------------------------------------------------------- Matches the first selected element. 返回值 Element 示例 查找表格的第一行 HTML 代码:
Header 1
Value 1
Value 2
jQuery 代码: $("tr:first") 结果: [ Header 1 ] :last:last 匹配找到的最后一个元素 -------------------------------------------------------------------------------- Matches the last selected element. 返回值 Element 示例 查找表格的最后一行 HTML 代码:
Header 1
Value 1
Value 2
jQuery 代码: $("tr:last") 结果: [ Value 2 ] :not(selector):not(selector) 去除所有与给定选择器匹配的元素 -------------------------------------------------------------------------------- Removes all elements matching the given selector. 返回值 Array 参数 selector (Selector) : 用于筛选的选择器 示例 查找所有未选中的 input 元素 HTML 代码: jQuery 代码: $("input:not(:checked)") 结果: [ ] :even:even 匹配所有索引值为偶数的元素,从 0 开始计数 -------------------------------------------------------------------------------- Matches even elements, zero-indexed. 返回值 Array 示例 查找表格的1、3、5...行(即索引值0、2、4...) HTML 代码:
Header 1
Value 1
Value 2
jQuery 代码: $("tr:even") 结果: [ Header 1, Value 2 ] :odd:odd 匹配所有索引值为奇数的元素,从 0 开始计数 -------------------------------------------------------------------------------- Matches odd elements, zero-indexed. 返回值 Array 示例 查找表格的2、4、6行(即索引值1、3、5...) HTML 代码:
Header 1
Value 1
Value 2
jQuery 代码: $("tr:odd") 结果: [ Value 1 ] :eq(index):eq(index) 匹配一个给定索引值的元素 -------------------------------------------------------------------------------- Matches a single element by its index. 返回值 Element 参数 index (Number) : 从 0 开始计数 示例 查找第二行 HTML 代码:
Header 1
Value 1
Value 2
jQuery 代码: $("tr:eq(1)") 结果: [ Value 1 ] :gt(index):gt(index) 匹配所有大于给定索引值的元素 -------------------------------------------------------------------------------- Matches all elements with an index above the given one. 返回值 Array 参数 index (Number) : 从 0 开始计数 示例 查找第二第三行,即索引值是1和2,也就是比0大 HTML 代码:
Header 1
Value 1
Value 2
jQuery 代码: $("tr:gt(0)") 结果: [ Value 1, Value 2 ] :lt(index):lt(index) 匹配所有小于给定索引值的元素 -------------------------------------------------------------------------------- Matches all elements with an index below the given one. 返回值 Array 参数 index (Number) : 从 0 开始计数 示例 查找第一第二行,即索引值是0和1,也就是比2小 HTML 代码:
Header 1
Value 1
Value 2
jQuery 代码: $("tr:lt(2)") 结果: [ Header 1, Value 1 ] :header:header 匹配如 h1, h2, h3之类的标题元素 -------------------------------------------------------------------------------- Matches all elements that are headers, like h1, h2, h3 and so on. 返回值 Array 示例 给页面内所有标题加上背景色 HTML 代码:

Header 1

Contents 1

Header 2

Contents 2

jQuery 代码: $(":header").css("background", "#EEE"); 结果: [

Header 1

,

Header 2

] :animated:animated 匹配所有没有在执行动画效果中的元素 -------------------------------------------------------------------------------- Matches all elements that are currently being animated. 返回值 Array 示例 只有对不在执行动画效果的元素执行一个动画特效 HTML 代码:
jQuery 代码: $("#run").click(function(){ $("div:not(:animated)").animate({ left: "+20" }, 1000); }); 内容 :contains(text):contains(text) 匹配包含给定文本的元素 -------------------------------------------------------------------------------- Matches elements which contain the given text. 返回值 Array 参数 text (String) : 一个用以查找的字符串 示例 查找所有包含 "John" 的 div 元素 HTML 代码:
John Resig
George Martin
Malcom John Sinclair
J. Ohn jQuery 代码: $("div:contains('John')") 结果: [
John Resig
,
Malcom John Sinclair
] :empty:empty 匹配所有不包含子元素或者文本的空元素 -------------------------------------------------------------------------------- Matches all elements that are empty, be it elements or text. 返回值 Array 示例 查找所有不包含子元素或者文本的空元素 HTML 代码:
Value 1
Value 2
jQuery 代码: $("td:empty") 结果: [ , ] :has(selector):has(selector) 匹配含有选择器所匹配的元素的元素 -------------------------------------------------------------------------------- Matches elements which contain at least one element that matches the specified selector. 返回值 Array 参数 selector (Selector) : 一个用于筛选的选择器 示例 给所有包含 p 元素的 div 元素添加一个 text 类 HTML 代码:

Hello

Hello again!
jQuery 代码: $("div:has(p)").addClass("test"); 结果: [

Hello

] :parent:parent 匹配含有子元素或者文本的元素 -------------------------------------------------------------------------------- Matches all elements that are parents - they have child elements, including text. 返回值 Array 示例 查找所有含有子元素或者文本的 td 元素 HTML 代码:
Value 1
Value 2
jQuery 代码: $("td:parent") 结果: [ Value 1, Value 1 ] 可见性 :hidden:hidden 匹配所有的不可见元素,input 元素的 type 属性为 "hidden" 的话也会被匹配到 -------------------------------------------------------------------------------- Matches all elements that are hidden, or input elements of type "hidden". 返回值 Array 示例 查找所有不可见的 tr 元素 HTML 代码:
Value 1
Value 2
jQuery 代码: $("tr:hidden") 结果: [ Value 1 ] :visible:visible 匹配所有的可见元素 -------------------------------------------------------------------------------- Matches all elements that are visible. 返回值 Array 示例 查找所有可见的 tr 元素 HTML 代码:
Value 1
Value 2
jQuery 代码: $("tr:visible") 结果: [ Value 2 ] 属性 [attribute][attribute] 匹配包含给定属性的元素 -------------------------------------------------------------------------------- Matches elements that have the specified attribute. 返回值 Array 参数 attribute (String) : 属性名 示例 查找所有含有 id 属性的 div 元素 HTML 代码:

Hello!

jQuery 代码: $("div[id]") 结果: [
] [attribute=value][attribute=value] 匹配给定的属性是某个特定值的元素 -------------------------------------------------------------------------------- Matches elements that have the specified attribute with a certain value. 返回值 Array 参数 attribute (String) : 属性名 value (String) : 属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。 示例 查找所有 name 属性是 newsletter 的 input 元素 HTML 代码: ' jQuery 代码: $("input[name='newsletter']").attr("checked", true); 结果: [ , ] [attribute!=value][attribute!=value] 匹配给定的属性是不包含某个特定值的元素 -------------------------------------------------------------------------------- Matches elements that don't have the specified attribute with a certain value. 返回值 Array 参数 attribute (String) : 属性名 value (String) : 属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。 示例 查找所有 name 属性不是 newsletter 的 input 元素 HTML 代码: ' jQuery 代码: $("input[name!='newsletter']").attr("checked", true); 结果: [ ] [attribute^=value][attribute^=value] 匹配给定的属性是以某些值开始的元素 -------------------------------------------------------------------------------- Matches elements that have the specified attribute and it starts with a certain value. 返回值 Array 参数 attribute (String) : 属性名 value ( String) : 属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。 示例 查找所有 name 以 'news' 开始的 input 元素 HTML 代码: jQuery 代码: $("input[name^='news']") 结果: [ , ] [attribute$=value][attribute$=value] 匹配给定的属性是以某些值结尾的元素 -------------------------------------------------------------------------------- Matches elements that have the specified attribute and it ends with a certain value. 返回值 Array 参数 attribute (String) : 属性名 value (String) : 属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。 示例 查找所有 name 以 'letter' 结尾的 input 元素 HTML 代码: jQuery 代码: $("input[name$='letter']") 结果: [ , ] [attribute*=value][attribute*=value] 匹配给定的属性是以包含某些值的元素 -------------------------------------------------------------------------------- Matches elements that have the specified attribute and it contains a certain value. 返回值 Array 参数 attribute (String) : 属性名 value (String) : 属性值。引号在大多数情况下是可选的。但在遇到诸如属性值包含"]"时,用以避免冲突。 示例 查找所有 name 包含 'man' 的 input 元素 HTML 代码: jQuery 代码: $("input[name*='man']") 结果: [ , , ] [selector1][selector2][selectorN][selector1][selector2][selectorN] 复合属性选择器,需要同时满足多个条件时使用。 -------------------------------------------------------------------------------- Matches elements that have the specified attribute and it contains a certain value. 返回值 Array 参数 selector1 (Selector) : 属性选择器 selector2 (Selector) : 另一个属性选择器,用以进一步缩小范围 selectorN (Selector) : 任意多个属性选择器 示例 找到所有含有 id 属性,并且它的 name 属性是以 man 结尾的 HTML 代码: jQuery 代码: $("input[id][name$='man']") 结果: [ ] 子元素 :nth-child(index/even/odd/equation):nth-child(index/even/odd/equation) 匹配其父元素下的第N个子或奇偶元素 ':eq(index)' 只匹配一个元素,而这个将为每一个父元素匹配子元素。:nth-child从1开始的,而:eq()是从0算起的! 可以使用: nth-child(even) :nth-child(odd) :nth-child(3n) :nth-child(2) :nth-child(3n+1) :nth-child(3n+2) -------------------------------------------------------------------------------- Matches the nth-child of its parent. While ':eq(index)' matches only a single element, this matches more then one: One for each parent. The specified index is one-indexed, in contrast to :eq() which starst at zero. 返回值 Array 参数 index (Number) : 要匹配元素的序号,从1开始 示例 在每个 ul 查找第 2 个li HTML 代码:
  • John
  • Karl
  • Brandon
  • Glen
  • Tane
  • Ralph
jQuery 代码: $("ul li:nth-child(2)") 结果: [
  • Karl
  • ,
  • Tane
  • ] :first-child:first-child 匹配第一个子元素 ':first' 只匹配一个元素,而此选择符将为每个父元素匹配一个子元素 -------------------------------------------------------------------------------- Matches the first child of its parent. While ':first' matches only a single element, this matches more then one: One for each parent. 返回值 Array 示例 在每个 ul 中查找第一个 li HTML 代码:
    • John
    • Karl
    • Brandon
    • Glen
    • Tane
    • Ralph
    jQuery 代码: $("ul li:first-child") 结果: [
  • John
  • ,
  • Glen
  • ] :last-child:last-child 匹配最后一个子元素 ':last'只匹配一个元素,而此选择符将为每个父元素匹配一个子元素 -------------------------------------------------------------------------------- Matches the last child of its parent. While ':last' matches only a single element, this matches more then one: One for each parent. 返回值 Array 示例 在每个 ul 中查找最后一个 li HTML 代码:
    • John
    • Karl
    • Brandon
    • Glen
    • Tane
    • Ralph
    jQuery 代码: $("ul li:last-child") 结果: [
  • Brandon
  • ,
  • Ralph
  • ] :only-child:only-child 如果某个元素是父元素中唯一的子元素,那将会被匹配 如果父元素中含有其他元素,那将不会被匹配。 -------------------------------------------------------------------------------- Matches the only child of its parent. If the parent has other child elements, nothing is matched. 返回值 Array 示例 在 ul 中查找是唯一子元素的 li HTML 代码:
    • John
    • Karl
    • Brandon

    28,391

    社区成员

    发帖
    与我相关
    我的任务
    社区描述
    ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
    社区管理员
    • ASP
    • 无·法
    加入社区
    • 近7日
    • 近30日
    • 至今
    社区公告
    暂无公告

    试试用AI创作助手写篇文章吧