您的浏览器过于古老 & 陈旧。为了更好的访问体验, 请 升级你的浏览器
Ready 发布于2014年08月17日 13:50

原创 jQuery 选择器(:file)详解

2263 次浏览 读完需要≈ 4 分钟

内容目录

jQuery的:file选择器用于匹配所有的文件域元素,将其封装为jQuery对象并返回。

文件域就是type为file的input标签:<input type="file">

语法

jQuery( ":file" )

返回值

返回封装了所有文件域元素的jQuery对象。

如果找不到任何相应的匹配,则返回一个空的jQuery对象。

示例&说明

以下面这段HTML代码为例:

<div id="n1">
	<form id="n2">
	   <input id="n3" type="button" value="Input Button"/>
	   <input id="n4" type="checkbox" />
	   <input id="n5" type="file" />
	   <input id="n6" type="hidden" />
	   <input id="n7" type="image" />
	   <input id="n8" type="password" />
	   <input id="n9" type="radio" />
	   <input id="n10" type="reset" />
	
	   <input id="n11" type="submit" />
	   <input id="n12" type="text" />
	   <select id="n13">
	   	<option id="n14">Option</option>
	   </select>
	   <textarea id="n15"></textarea>
	   <button id="n16" type="submit">Button</button>
	</form>
</div>

现在,我们查找所有的文件域,即可编写如下jQuery代码:

// 选择了id为n5的一个元素
$(":file");

运行代码

  • CodePlayer技术交流群1
  • CodePlayer技术交流群2

0 条评论

撰写评论

打开导航菜单