博主信息
博文 34
粉丝 0
评论 1
访问量 29115
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
jQuery中的基本操作(二) —2018年9月18日23时45分
感恩的心的博客
原创
849人浏览过

实战: 在线相册


实例

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>jQuery Ablum</title>
        <Script src="../0917/lib/jquery.js"></Script>
            <style>
        .warp {
            width: 360px;
            height: auto;
            background-color: #efefef;
            border: 3px double grey;
            color: #363636;
            border-radius: 2%;
        }
        .warp .header {
            padding: 15px;
        }
        .warp .header h2 {
            text-align: center;
        }
        .add {
            width: 100px;
            height: 30px;
            border: none;
            cursor: pointer;
            background-color: skyblue;
            color: white;
        }
        .add:hover {
            background-color: orange;
            font-size: 1.1rem;
        }
        .main {
            overflow: hidden;
        }

        .main ul {
            padding: 0;
            margin: 0;
        }

        .main ul li {
            list-style-type: none;
            float: left;
            margin-left: 20px;
            margin-bottom: 10px;
            width: 150px;
            height: 200px;
            text-align: center;
        }

        .main ul li button {
            margin: 3px;
            border: none;
            border-radius: 5%;
            background-color: lightgreen;
        }
        .main ul li button:hover {
            background-color: orange;
            color: white;
            cursor: pointer;
        }

    </style>
    </head>
    <body>
        <div class="warp">
            <div class="header">
                <h2>Good Person</h2>
                <p>
                <lable for="img_url">Please Choose Picture</lable>
                <input type="file" name="img_url" id="img_url" placeholder="address">
                </p>
                <p>
                    Picture Style:
                    <input type="radio" id="rect" name="border" value="0"><label for="rect">Orthogonal Angel</label>
                    <input type="radio" id="radius" name="border" value="10%"><label for="radius">Fillet Angel</label>
                    <input type="radio" id="circle" name="border" value="50%"><label for="circle">Cycle</label>
                </p>
                <p>Shadow:
                    <select name="shadow">
                        <option value="0">Not Add</option>
                        <option value="1">Add</option>
                    </select>
                </p>
                <p><button class="add">Add picture</button></p>
            </div>
            <div class="main">
                <ul>
                    <!--<li>-->
                    <!--<img src="" alt="">-->
                    <!--<button>前</button>-->
                    <!--<button>后</button>-->
                    <!--<button>删</button>-->
                    <!--</li>-->
                </ul>
            </div>
        </div>

        <script>
            $(function(){

                $('button.add').on('click',function(){
                    let img_url=$('#img_url').val();
                    console.log('url1:'+img_url);
                    if(0===img_url.length){
                        alert('Please choose a picture.');
                        $('#img_url').focus();
                        return false;
                    }
                

                //get style of picture
                let img_type=$(':radio:checked').val();
                let shadow='none';
                if($(':selected').val()==='1'){
                    shadow='3px 3px 3px #666';
                }

                //Create picture and add to the page
                console.log('url2:'+img_url);
                img_url = 'http://www.php.io/0918/images/'+img_url.split('\\')[2];
                console.log(img_url);

                //Create a picture
                let img=$('<img/>')
                        .prop('src',img_url)
                        .width(150)
                        .height(150)
                        .css({
                            'border-radius':img_type,
                            'box-shadow':shadow
                        });

                let before=$('<button></button>').text('前移');
                let after=$('<button></button>').text('后移');
                let remove=$('<button></button>').text('删除');

                let container=$('<li>');
                container.append(img,before,after,remove);
                container.appendTo('ul');

                before.click(function(){
                    let current=$(this).parent();
                    let prev=current.prev();
                    prev.before(current);
                });

                after.click(function(){
                    let current=$(this).parent();
                    let next=current.next();
                    next.after(current);
                });


                remove.click(function(){
                    if (confirm('确认删除吗?')) {
                        $(this).parent().remove();
                    }
                    return false;
                });




});


            });


        </script>


    </body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学