功能需求:
点击添加按钮的时候,会添加一行input输入框,使用jquery来实现一下。虽然现在前端开发小伙伴们都不用jquery了,但是,我还是决定要记录一下这个小demo,因为用到的比较多。
示例代码:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<style>
</style>
</head>
<body>
<div id="timeCont"></div>
<button type="button" class="btn blue" id="fatBtn">新增区域</button>
<script type="text/javascript">
/* 新增检测时间 */
$("#fatBtn").click(function() {
var htm = "";
htm += "<div class='form-group'>";
htm += "<label class='col-sm-3 control-label' >区域监测时间段:</label>";
htm += "<div class='col-sm-4'>";
htm += "<input type='text' class='form-control sleepStart1' name='startTime' value='09:00' ></input>";
htm += "</div>";
htm += "<div class='col-sm-4'>";
htm +="<input type='text' class='form-control sleepStop1' name='stopTime' value='17:00'></input>";
htm += "</div>";
htm += "</div>";
$('#timeCont').append(htm);
});
</script>
</html>
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。