最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

基于jQuery选择器之表单对象属性筛选选择器的实例

来源:懂视网 责编:小采 时间:2020-11-27 22:29:29
文档

基于jQuery选择器之表单对象属性筛选选择器的实例

基于jQuery选择器之表单对象属性筛选选择器的实例: <!DOCTYPE html> <html> <head> <meta http-equiv=Content-type content=text/html; charset=utf-8 /> <title></title> <link rel=stylesheet href=imooc.css rel=external nofollow type=text/css>
推荐度:
导读基于jQuery选择器之表单对象属性筛选选择器的实例: <!DOCTYPE html> <html> <head> <meta http-equiv=Content-type content=text/html; charset=utf-8 /> <title></title> <link rel=stylesheet href=imooc.css rel=external nofollow type=text/css>

<!DOCTYPE html>
<html>

<head>
 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
 <title></title>
 <link rel="stylesheet" href="imooc.css" rel="external nofollow" type="text/css">
 <style>
 input {
 display: block;
 margin: 10px;
 padding: 10px;
 }
 </style>
 <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>

<body>
 <h2>子元素筛选选择器</h2>
 <h3>enabled、disabled</h3>
 <form>
 <input type="text" value="未设置disabled" />
 <input type="text" value="设置disabled" disabled />
 <input type="text" value="未设置disabled" />
 </form>

 <script type="text/javascript">
 //查找所有input所有可用的(未被禁用的元素)input元素。
 $("input:enabled").css("border", "2px groove red");
 </script>

 <script type="text/javascript">
 //查找所有input所有不可用的(被禁用的元素)input元素。
 $("input:disabled").css("border", "2px groove blue");
 </script>

 <h3>checked、selected</h3>
 <form>
 <input type="checkbox" checked="checked">
 <input type="checkbox">
 <input type="radio" checked> 
 <input type="radio">
 
 <select name="garden" multiple="multiple">
 <option>imooc</option>
 <option selected="selected">慕课网</option>
 <option>aaron</option>
 <option selected="selected">博客园</option>
 </select>

 </form>

 <script type="text/javascript">
 //查找所有input所有勾选的元素(单选框,复选框)
 //移除input的checked属性
 $("input:checked").removeAttr('checked')
 </script>

 <script type="text/javascript">
 //查找所有option元素中,有selected属性被选中的选项
 //移除option的selected属性
 $("option:selected").removeAttr('selected')
 </script>

</body>

</html>

注意:

在某些浏览器中,选择器:checked可能会错误选取到<option>元素,所以保险起见换用选择器input:checked,确保只会选取<input>元素

以上这篇jQuery选择器之表单对象属性筛选选择器实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

文档

基于jQuery选择器之表单对象属性筛选选择器的实例

基于jQuery选择器之表单对象属性筛选选择器的实例: <!DOCTYPE html> <html> <head> <meta http-equiv=Content-type content=text/html; charset=utf-8 /> <title></title> <link rel=stylesheet href=imooc.css rel=external nofollow type=text/css>
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top