JQuery-change/select/submit

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>change/select/submit</title>
</head>
<body>
<form action="www.baidu.com" method="get">
<input type="text" value="123">
<input type="submit" value="提交"></input>
    </form>
<select name="alex" id="">
    <option selected>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>

</select>
<script src="js/jQuery3.3.1.js"> </script>
<script>
    $(function () {
        $("input[type=text]").focus() ;  //获取焦点
        $("input[type=text]").change(  //change(表单控件的value发生改变时候)
            function () {
                console.log($("input[type=text]").val())
            }
        );
        $("input[type=text]").select(function () {  //select 文本被选中
            console.log("选中了")
        });
        $("select").change(
            function () {
                console.log($("select").find("option:selected").text()) //获取选中的值 需要获取select才能获取option
            }
        );

        $("form").submit(   //表单控件提交 是  获取表单事件
            function () {             
                alert(`确认提交?`)
            }
        )
    })
</script>
</body>
</html>

 

posted @ 2018-11-15 20:24  python传言  阅读(279)  评论(0编辑  收藏  举报