美文网首页
2019-04-28atter()和val()

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

作者: 果冻_4c9b | 来源:发表于2019-04-28 19:21 被阅读0次
    <!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>
    

    相关文章

      网友评论

          本文标题:2019-04-28atter()和val()

          本文链接:https://www.haomeiwen.com/subject/mzwjnqtx.html