实例
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>在线相册管理</title> <style> .warp { width: 620px; min-height: 30px; margin: 20px auto; align-content: center; background-color: lightyellow; } </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"><label>直角</label> <input type="radio" id="radius" name="border" value="10%"><label>圆角</label> <input type="radio" id="circle" name="border" value="50%"><label>圆形</label> </p> <p> 是否添加阴影: <select name="shadow"> <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="./lib/jquery.js"></script> <script> $('button.add').on('click',function f() { //判断是否有图片地址存在 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'; } //创建图片并添加到页面中 let img_url = 'http://127.0.0.1/0918/'+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('删除'); $('<li>').append(img,before,after,remove).appendTo('ul'); remove.click(function () { alert('是否删除'); }); }) </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例