批改状态:未批改
老师批语:
实战: 在线相册
<!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>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号