jQuery-表单选择器

1.表单概念

:text        找所有的type="text"的input标签
:radio       type="radio"的单选按钮
:checkbox    type="cheakbox"的多选按钮
:checked     被选中的

2.代码展示

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表单选择器</title>
</head>

<body>
    <input type="radio" name="sex" value="1" />男
    <input type="radio" name="sex" value="2" />女
    <button id="btn">提交</button>
</body>
<srcipt src=" https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></srcipt>
<script>
    $("#btn").click(function() {
        console.log($(":radio:checked").val())
    })
</script>

</html>

猜你喜欢

转载自www.cnblogs.com/dongxuelove/p/12933301.html