카테고리 없음

jQuery Form (focus, blur, select, enevnt.tartget, change,submit)

Canyi 2022. 11. 4. 10:16

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>폼폼</title>
    <script src="https://code.jquery.com/jquery-latest.min.js"></script>
    <style>
        span{
            color: white;
            background-color: cornflowerblue;
        }
    </style>
</head>
<body>
    <p>
        <input type="text">   
        <span></span> 
    </p>


    <script>
        $('input').focus(function(){
            $(this).next('span').html('focus');
        })        
        .blur(function(){
            $(this).next('span').html('blur');
        })
        .change(function(event){
            $(this).next('span').html($(event.target).val());
        }) 
        .select(function(){
            $(this).next('span').html('select');
        }) 
        
        // .change(function(){
        //     $(this).next('span').html('change');
        // }) 
        // .select(function(){
        //     $(this).next('span').html('select');
        // }) 
    </script>
</body>
</html>

focus

textinput 안을 클릭할 경우

blur

textinput 밖을 클릭할 경우

enevnt.target.val()

tetxinput 값을 변경하고 enter할경우

select

textinput 값을 선택할 경우

 

 

 

submit

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>submit</title>
    <script src="https://code.jquery.com/jquery-latest.min.js"></script>
    <style>
        p{
            margin: 0;
            color: black;
        }
        div{
            margin-left: 10px;
        }
        span{
            color: white;
            background-color: cornflowerblue;
        }
    </style>
</head>
<body>

    <p>
        Type 'correct' to validate.
    </p>

    <form>
        <div>
            <input type="text">   
            <input type="submit", value="질의보내기">
        </div>
    </form>
    <span></span>
    <script>
        $('form').submit(function () {
            if($('input:first').val() == 'correct')
            {
                // $('span').text('validated...').show().fadeIn(1000);
                $('span').text('validated...').show();
                return false;
            }
            else
            {
                $('span').text('not validated...').show().fadeOut(2000);
                return false;
            }
        })
    </script>
</body>
</html>

입력한 값이 correct가  아닐 경우 2동안 서서히 사라짐