Correction status:Uncorrected
Teacher's comments:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>动态相册管理器</title> <style> .warp { width: 360px; height: auto; background-color: linen; border: 3px double grey; color: #363636; border-radius: 2%; box-shadow: 2px 2px 2px #888; } .warp .header { padding: 15px; } .warp .header h2 { text-align: center; } .add { width: 100px; height: 30px; border: none; cursor: pointer; background-color: deepskyblue; 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: deepskyblue; } .main ul li button:hover { background-color: orange; color: white; cursor: pointer; } </style> </head> <body> <div class="warp"> <div class="header"> <h2>私人相册</h2> <p> <label for="img_url">输入图片地址</label> <input type="file" name="img_url" id="img_url" placeholder="图片地址"> </p> <p> 图片类型: <input type="radio" id="rect" name="border" value="0" checked><label for="rect">直角</label> <input type="radio" id="radius" name="border" value="10%"><label for="radius">圆角</label> <input type="radio" id="circle" name="border" value="50%"><label for="circle">圆形</label> </p> <p> <label for="shadow">是否添加阴影:</label> <select name="shadow" id="shadow"> <option value="0" selected>不添加</option> <option value="1">添加</option> </select> </p> <p><button class="add">添加图片</button></p> </div> <div class="main"> <ul> <!-- <li>--> <!-- <img src="http://html.io/0521/static/images/2.jpg" alt="" width="150">--> <!-- <button>前移</button>--> <!-- <button>后移</button>--> <!-- <button>删除</button>--> <!-- </li>--> </ul> </div> </div> <script src="static/js/jquery-3.4.1.js"></script> <script> $('.add').on('click',function(){ //1.获取图片 var img_url = $('#img_url').val(); if (img_url.trim().length === 0) { alert('请先选择一张图片!'); $('#img_url').focus(); return false; } //2.获取图片外观设定 var img_type = $('input[type="radio"]:checked').val(); //是否添加阴影 var shadow = 'none'; if ($(':selected').val() === '1') { shadow = '2px 2px 2px #888'; } // console.log(img_url); // // console.log(img_url.split('\\')); //图片路径 // img_url 是一个图片的本地化的地址, 不能直接使用,需要进行转换 // split(): 将一个字符串,按指定字符,切割成数组 var realImgUrl = img_url.split('\\')[2]; // console.log(realImgUrl); img_url = 'http://html.io/0521/static/images/'+realImgUrl; // console.log(img_url); //创建图片与按钮,并打包到一个容器中,添加到页面列中 var img = $('<img>') .attr({ src : img_url, width : 150, height : 150, alt: '明星相册' }) .css({ 'border-radius': img_type, 'box-shadow': shadow }); //创建三个按钮 前移,后移,删除 var before = $('<button></button>').text('前移'); var after = $('<button></button>').text('后移'); var remove = $('<button></button>').text('删除'); //创建一个li用来放所有内容 var contaier = $('<li>'); contaier.append(img,before,after,remove); contaier.appendTo('ul'); //三按钮功能 //前移 before.on('click',function(){ var current =$(this).parent(); var prev =current.prev(); prev.before(current); }); //后退 after.on('click',function(){ var current =$(this).parent(); var next =current.next(); next.after(current); }); //删除 remove.on('click',function() { if (confirm("确认删除吗?")) { $(this).parent().remove(); } return false; }) }) </script> </body> </html>
点击 "运行实例" 按钮查看在线实例