博主信息
博文 35
粉丝 0
评论 0
访问量 33857
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
图片的动态添加与动态删除
小的博客
原创
915人浏览过

html布局css进行样式美化;代码运行结果预览QQ截图20171222141743.png

<!DOCTYPE html>
<html>
 <meta charset="UTF-8">
 <head><title></title>
  <script src=" https://code.jquery.com/jquery-3.2.1.min.js"></script>
  <style>
  *{
   padding:0;
   margin:0;
  }
   .select{
    width:500px;
 height:100%;
 background-color:antiquewhite;
 margin:0 auto;
 border-radius:10px;
   }
   .p1{
    width:500px;
 height:30px;
 line-height:40px;
 padding-top:20px;
 margin-left:20px;
 color:#777;
   }
   .p1 input{
    width:200px;
 height:25px;
 border-radius:5px;
   }
   .p2{
    width:500px;
 height:40px;
 margin-top:20px;
 margin-left:20px;
 color:#777;
   }
   p button{
   width:200px;
   height:35px;
   margin-left:150px;
   margin-bottom:20px;
   border-radius:5px;
   }
   #result{
    width:500px;
 height:100%;
    margin:0 auto;
 
   }
   #result img{
    box-show:5px 5px 5px #666;
   }
  </style>
 </head>
 <body>
  <div>
   <div class='select'>
  <p class="p1">请输入图片地址:&nbsp;<input type="text" name="url" value=""></p>
  <p class="p2">&nbsp;相&nbsp;框&nbsp;类&nbsp;型:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="radio" name="border"id='zj' value='0' checked><label for='zj'>直角</label>
   <input type="radio" name="border" id='yj' value="30"><label for="yj">圆角</label>
   <input type="radio" name="border" id='yx' value="100"><label for="yx">圆形</label>
  </p>
  <p><button class="add">添加</button></p>
  </div>
 <div id="result">
  
 </div>

使用jquery方法:实现图片的添加(设置添加图片显示的时间是3秒),上移,下移,删除(设置删除图片消失的时间是2秒);

</div>
  <script>
  $(function(){
   
   $('.add').on('click',function(){
    var imgUrl=$('.select input[name="url"]').val();//获取图片地址
      // alert(imgUrl)检查是否获取到图片地址
   //获取边框
   var  borderBox=$('.select input[name="border"]:checked').val();
  // alert(borderBox)//检查是否获取到边框
   var img=$('<img>').attr('src',imgUrl);
      img.css('border-radius',borderBox+'px');
   var btnup=$('<button>上移</button>');
   var btndown=$('<button>下移</button>');
   var remove=$('<button>删除</button>');
   var imgBox=$('<div></div>');
       imgBox.append(img,btnup,btndown,remove);
    $('#result').append(imgBox).css('display','none').show(3000);//图片显示时间3秒
    btnup.on('click',function(){
      imgBox.prev().before(imgBox);
    })
    btndown.on('click',function(){
      imgBox.next().after(imgBox);
    })
    remove.on('click',function(){
      imgBox.toggle(2000);//图片删除时间是2秒
    })
  
   })
  
  })
  </script>
 </body>
</html>


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

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

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