打印輸入表單中的內容

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

<head>
    <meta charset="UTF-8">
    <title>CSS選擇器</title>
</head>

<body>
    <form>
        <p>
            <label for="username">用戶名</label>
            <input type="text" id="username" placeholder="請輸入用戶名">
        </p>
        <p>
            <label for="nickname">暱稱</label>
            <input type="text" id="nickname" placeholder="輸入一個暱稱">
        </p>
        <p>
            <label for="password">密碼</label>
            <input type="password" id="password">
        </p>
        <p>
            <label for="passwordchecked">確認密碼</label>
            <input type="password" id="passwordchecked">
        </p>
        <p>
            <label for="sex">性別</label>
            <select id="sex">
                <option value="male">男</option>
                <option value="female">女</option>
            </select>
        </p>
        <p>
            <label for="">愛好</label>
            <label>
                <input type="checkbox" name="dx" value="1">旅遊</label>
            <label>
                <input type="checkbox" name="dx" value="2">睡覺</label>
            <label>
                <input type="checkbox" name="dx" value="3">上網</label>
                <label>
                <input type="checkbox" name="dx" value="4">看電影</label>
        </p>
        <p>
            <label for="">是否已婚</label>
            <label>
                <input type="radio" value="1" name="married">是</label>
            <label>
                <input type="radio" value="0" name="married">否</label>
        </p>
        <div class="center">
            <input type="hidden" value="註冊表單">
            <input type="button" value="返回" />
            <button type="submit">提交</button>
            <button type="reset">重置</button>
        </div>
    </form>
    <div class="msg"></div>
</body>

</html>

 

<script src="../jquery-1.12.0.js"></script>

 

 <script type="text/javascript">
    $(function(){
        // @做業
        // 點擊提交按鈕時,把輸入的內容按順序放到.msg 
        $('form').css('float', 'left');
        $('.msg').css({float:'right',width:400,height:400,background:'#89abec',padding:20});
        $(':submit').click(function(e){console.log(111)
            e = e || window.event
             var username = $('#username').val()
             var nickname = $('#nickname').val()
             var password = $('#password').val()
             var sex = $('select option:selected').text()

             var arr1 = []
             $('input[type = "checkbox"]:checked').each(function(){
                arr1.push($(this).parent().text())
             })
             var radio = $('input[type="radio"]:checked').parent().text()


            $('.msg').html('用戶名:' +username+ '<br>暱稱:' +nickname+ '<br>密碼:' +password+ '<br>性別:' +sex+ '<br>愛好:'+ arr1+ '<br>是否已婚:' +radio)  
            
            e.preventDefault()

        })
    })
    </script>

 

打印輸入表單中的內容javascript

css

html

java

jquery

this

orm

htm

相關文章
相關標籤/搜索