动态div设置滚动条overflow-y: scroll

例子很简单,就是给没有height的div在一定高度时设置滚动条。

style部分:

<style>
.showInput{width: 300px;height: 30px;font-size: 20px;line-height: 30px;}
.greyBox{position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-color: #ccc;opacity: 0.6;display: none;z-index: 8888;}
.productionBox{position: fixed;width: 600px;top: 10%;left: 50%;margin-left: -300px;border: 1px solid #e3e5f1;background-color: #fff;display: none;z-index: 9999;}
.title{width: 600px;text-align: center;height: 40px;line-height: 40px;font-size: 18px;font-weight: bold;}
.butBox{margin:15px;}
.butBox .addOnly{width: 60px;margin-right: 15px;margin-bottom: 10px;}
.addMain .inputBox{padding-left: 15px;margin-top: 10px;}
.addMain .inputBox input{width: 45%;height: 25px;line-height:25px;font-size: 16px;margin-left: 5px;margin-right: 5px;}
.operation{width: 600px;margin-top: 20px;margin-bottom: 20px;padding-left: 200px;}
.operation .btnConfirm{margin-right: 30px;}
</style>
html部分:
<input type="text" placeholder="请双击" class="showInput">
<!--隐藏的遮罩层-->
<div class="greyBox"></div>
<!--隐藏的生产批次选择窗口-->
<div class="productionBox" style="overflow-y: scroll;overflow-x: hidden; max-height:400px;"> //设置最大高度400px时,出现滚动条
<div class="title">编辑窗口</div>
<hr style="border: 1px dashed #ecf1f5;"/>
<div class="butBox">
<button class="addOnly addProduction">添加</button>
<button class="addOnly delProduction">删除</button>
</div>
<div class="addMain">
</div>
<div class="operation" >
<button class="btnConfirm">确定</button>
<button class="btnQuxiao">取消</button>
</div>
</div>
script部分:
<script type="text/javascript" src="jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$(function () {
//生产批次选框触发事件
$(".showInput").on("dblclick",function () {
$(this).blur();
$(".greyBox").show();//遮罩显现
$(".productionBox").show();
});
//添加按钮触发事件
$(".addProduction").on("click",function () {
var str = "";
str = "<div class='inputBox'>" +
"<input type='text' class='content' placeholder='请输入内容'>" +
"</div>";
$(".addMain").append(str);
});
//删除按钮触发事件
$(".delProduction").on("click",function () {
$(".addMain").children(":last").remove();
});

//确认按钮触发事件
$(".btnConfirm").on("click",function () {
var str='';
$(".content").each(function(){
str += $(this).val()+",";
});
str = str.substring(0,str.length - 1); //拼接input内值的字符串
$(".showInput").val(str).focus();
$(".greyBox").hide();
$(".productionBox").hide();
});
//取消按钮触发事件
$(".operation .btnQuxiao").on("click",function () {
$(".greyBox").hide();
$(".productionBox").hide();
$(".showInput").focus();
});
})
</script>
以上仅供参考!

转载于:https://www.cnblogs.com/lingdu87/p/7833561.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值