js进阶 10-11  表单伪类选择器的作用

一、总结

一句话总结:能想到用伪类选择器来解决问题。如果能一次记住自然是最棒的。

1、表单伪类选择器分为哪两类?

表单元素和表单属性,表单元素例如input,表单属性例如disabled

2、表单属性伪类选择器有哪四种(重要)?

可用的,不可用的,下拉列表选择的,单选复选选中的(就是我一直弄的那个功能)

表单属性伪类选择器

  • :enabled选择所有可用input元素
  • :disabled所有禁用的input元素
  • :selected选择所有被选中的option元素
  • :checked选择所被选中的表单元素,一般用于radio和checkbox

3、表单标签伪类选择器的作用?

选择表单里面的任何类型的元素,也可以选择显示和隐藏

26 $(':input').css('background','#ccc')

27 $(':button').css('background','green')

4、表单标签伪类选择器有哪些?

所有的表单元素

二、表单伪类选择器的作用

1、相关知识

  • 表单伪类选择器

    • : Input选择所有input元素
    • :button选择所有type="button"的input元素
    • :submit选择所有type="submit"的input元素
    • :reset选择所有type="reset"的input元素
    • :text选择所有单选文本框
    • :textarea选择所有多行文本框
    • :password选择所有密码文本框
    • :radio选择所有单选按钮
    • :checkbox选择所有复选框
    • :image选择所有图像域
    • :hidden选择所有隐藏域
    • :file选择所有文件域
  • 表单属性伪类选择器
    • :enabled选择所有可用input元素
    • :disabled所有禁用的input元素
    • :selected选择所有被选中的option元素
    • :checked选择所被选中的表单元素,一般用于radio和checkbox

2、代码

10-11代码

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>演示文档</title>
<script src="jquery-3.1.1.min.js"></script>
</head>
<body>
<form action="#">
<p>用户名:<input type="text" name="username"></p>
<p>密 码:<input type="password" name="password"></p>
<p>爱 好:<br>
<input type="radio" name="rad" value="A">新闻<br>
<input type="radio" name="rad" value="B">小说<br>
<input type="radio" name="rad" value="C">音乐<br>
</p>
<p>上传头像:<input type="file"></p>
<p>
<input type="reset" value="重置">
<input type="submit" value="提交">
<input type="button" value="按钮1">
<button type="button">按钮2</button>
</p>
</form>
<script>
$(':input').css('background','#ccc')
$(':button').css('background','green')
$(':submit').css('background','blue')
$(':text').css('background','#fcc')
$(':password').css('background','#fcc')
$(':radio').hide(3000)
$(':radio').show(3000)
$(':file').css('background','orange')
</script>
</body>
</html>

10-12代码

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>演示文档</title>
<script src="jquery-3.1.1.min.js"></script>
</head>
<body>
<form action="#">
<p>用户名:<input type="text" name="username"></p>
<p>密 码:<input type="password" name="password"></p>
<p>爱 好:<br>
<input type="radio" name="rad" value="A" checked="">新闻
<input type="radio" name="rad" value="B">小说
<input type="radio" name="rad" value="C">音乐
<input type="button" class="btn1" value="隐藏单选框">
</p>
<p>
<input type="reset" value="重置" disabled="">
<input type="submit" value="提交">
</p>
<select onchange="selVal()" >
<option value="列表项1">列表项1</option>
<option value="列表项2">列表项2</option>
<option value="列表项3">列表项3</option>
</select>
</form>
<script>
$(':enabled').css('background','#ccc')
$(':disabled').css('background','green')
$('.btn1').click(function(){
$(':checked').hide()
}) function selVal(){
var str=$(':selected').val()
alert(str)
}
</script>
</body>
</html>
 
 
 
0 Links

 
 

js进阶 10-11/12 表单伪类选择器的作用的更多相关文章

  1. js进阶 10-9 -of-type型子元素伪类选择器

    js进阶 10-9 -of-type型子元素伪类选择器 一.总结 一句话总结:三种和first.last等有关的选择器. 1.:first和:first-child和:first-of-type的区别 ...

  2. js进阶 10-10 可见伪类选择器和内容伪类选择器的作用

    js进阶 10-10  可见伪类选择器和内容伪类选择器的作用 一.总结 一句话总结:分组来描述.内容伪类选择器就是  四个  包含.可见的伪类选择器就是可见和不可见.查找功能,也就是内容伪类选择器非常 ...

  3. js 进阶 10 js选择器大全

    js 进阶 10 js选择器大全 一.总结 一句话总结:和css选择器很像 二.JQuery选择器 原生javaScript中,只能使用getELementById().getElementByNam ...

  4. js进阶 10-8 伪类选择器有哪几类(自己不用,永远不是自己的)

    js进阶 10-8 伪类选择器有哪几类(自己不用,永远不是自己的) 一.总结 一句话总结:自己不用,永远不是自己的. 0.学而不用,却是为何? 自己不用,永远不是自己的,有需求的时候要想到它,然后操作 ...

  5. 彻底搞懂CSS伪类选择器:is、not

    本文介绍一下Css伪类:is和:not,并解释一下is.not.matches.any之前的关系 :not The :not() CSS pseudo-class represents element ...

  6. CSS伪类选择器:is、not

    本文介绍一下Css伪类:is和:not,并解释一下is.not.matches.any之前的关系 :not The :not() CSS pseudo-class represents element ...

  7. CSS3新增的伪类选择器

    伪类选择器的作用:对已有选择器做进一步的限制,对已有选择器能匹配的元素做进一步的过滤.CSS 3提供的伪类选择器主要分为以下三类: 结构性伪类选择器 UI元素状态伪类选择器 其他伪类选择器 1.结构性 ...

  8. JS表单验证类HTML代码实例

    以前用的比较多的一个JS表单验证类,对于个人来说已经够用了,有兴趣的可以在此基础上扩展成ajax版本.本表单验证类囊括了密码验证.英文4~10个 字符验证. 中文非空验证.大于10小于100的数字.浮 ...

  9. atitit.Oracle 9 10 11 12新特性attilax总结

    atitit.Oracle 9  10 11  12新特性 1. ORACLE 11G新特性 1 1.1. oracle11G新特性 1 1.2. 审计 1 1.3. 1.   审计简介 1 1.4. ...

随机推荐

  1. [React & Testing] Snapshot testings

    For example we have a React comonent: -- A toggle button, we want to test. When it si toggle on, the ...

  2. BFS模版程序

    本文转自q=bfs&u=cnyali&t=blog">http://so.csdn.net/so/search/s.do?q=bfs&u=cnyali& ...

  3. textview-显示行数限制

    在代码中直接添加 android:maxLines="2" android:ellipsize="end" 跟ellipsize搭配使用,超过两行的时候,第二行 ...

  4. Android Intent的setClass和setClassName的区别

    setClass:跳转到与该工程下的(同一个Application中的)activity或者service setClassName:跳转到不同Applicaiton的activity或者servic ...

  5. 无法显式调用运算符或访问器 错误处理方法 DLL study

    无法显式调用运算符或访问器 错误处理方法 转 无法显式调用运算符或访问器 错误处理方法 反汇编一个dll类库,导出的项目会报出很多bug,其中主要的就是“无法显式调用运算符或访问器”这个错误,看了一下 ...

  6. Project Euler 363 Bézier Curves(几何+二分)

    题目链接: https://projecteuler.net/problem=363 题目: A cubic Bézier curve is defined by four points: \(P_0 ...

  7. JS错误记录 - 事件 - 拖拽

    错误总结: 1. var disX = 0;   现在window.onload里声明变量,而不是在事件oDiv.onmousedown里面声明并赋值. 对于这个还不是很明白. 2. onmoused ...

  8. .NetCore微服务Surging新手傻瓜式 入门教程 学习日志---先让程序跑起来(一)

    原文:.NetCore微服务Surging新手傻瓜式 入门教程 学习日志---先让程序跑起来(一) 写下此文章只为了记录Surging微服务学习过程,并且分享给广大想学习surging的基友,方便广大 ...

  9. python整除

    1.'/'除号与c不同,单个'/'是浮点除,两个除号'//'才是整除

  10. [React Intl] Format a Date Relative to the Current Date Using react-intl FormattedRelative

    Given a date, we’ll use the react-intl FormattedRelative component to render a date in a human reada ...