实战编程: 武林高手在线相册
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>女侠排行榜</title> <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>女侠排行榜</h2> <p> <lable for="img_url">请选择一张图片:</lable> <input type="file" name="img_url" id="img_url"> </p> <p> 图片类型: <input type="radio" id="direct" name="border" value="0"><lable for="direct">直角</lable> <input type="radio" id="radius" name="border" value="10%"><lable for="radius">圆角</lable> <input type="radio" id="circle" name="border" value="50%"><lable for="circle">正圆</lable> </p> <p> 是否添加阴影: <select name="shadow" id=""> <option value="0">有阴影</option> <option value="1">无阴影</option> </select> </p> <p><button class="add">添加图片</button></p> </div> <div class="main"> <ul></ul> </div> </div> <script src="../jquery.js"></script> <script > $(function () { $('button.add').on('click',function () { let img_url = $('#img_url').val(); if (img_url.length === 0){ alert('请选择一张图片'); $('#img_url').focus(); return false; } let img_type = $(':radio:checked').val(); let shadow = 'none'; if ($(':selected').val() === '1') { shadow = '3px 3px 3px #666;' } // console.log('http://jq.io/0918/images/'+img_url.split('\\')[2]); img_url = 'http://jq.io/0918/img/'+img_url.split('\\')[2]; 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 contaier = $('<li>'); contaier.append(img,before,after,remove); contaier.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>
点击 "运行实例" 按钮查看在线实例
PS:九一八,国耻日,不忘历史,民族复兴