2019-04-28atter()和val()

2019-04-28  本文已影响0人  果冻_4c9b
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style type="text/css">
            span{
                cursor: pointer;
            }
            div {
                width: 100px;
                height: 100px;
                border: 1px solid black;
                display: inline-block;
                cursor: pointer;
            }
        </style>
        <script src="../js/jquery.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
            $(function() {
               $('button').click(function(){
                   $('#box').css('background',$('input').val()).attr('class','test');//添加
                   alert( $('#box').attr('id'));//显示
               });
            })
        </script>

    </head>
    <body>
        <p>
        <input type="text" name="" id="" value="" />
        <button type="button">切换</button>
        </p>
        <div id="box"></div>
    </body>
</html>
上一篇下一篇

猜你喜欢

热点阅读