js开发的日历组件如何引入需要的html页面呢?

javascript 复制代码
<!DOCTYPE html>
<html>

<head>
	<title>日历页面</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://cdn.staticfile.net/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
	<link rel="stylesheet" href="./dialoge.css">
	<script src="https://cdn.staticfile.net/jquery/3.2.1/jquery.min.js"></script>
	<script src="./dialoge.js"></script>
	<!-- <script src="https://cdn.staticfile.net/popper.js/1.15.0/umd/popper.min.js"></script> -->
	<!-- <script src="https://cdn.staticfile.net/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> -->
	<style type="text/css">
		.today {
			width: 500px;
			text-align: center;
			margin-top: 10px;
			margin-bottom: 10px;
			/* border: solid 1px red; */
		}

		#container {
			position: relative;
		}
	</style>
</head>

<body>
	<div class="today" id="today">
		今天是那天?
		<input type="text" id="myInput" value="ceshi" onblur="handleBlur()">
	</div>
</body>
<script type="text/javascript">


	function onload(params) {
		// 获取input元素
		var input = document.getElementById('myInput');

		// 添加聚焦事件监听器
		input.addEventListener('focus', function () {
			let div = renderNode()
			console.log('Input is focused!');
			console.log(div);
			var myInput = document.getElementById('today');
			myInput.appendChild(div);
		});

	}
	function handleBlur(params) {
		var parentDiv = document.getElementById('today');
		var childDiv = document.querySelector('.calendar-box');
		if (childDiv && childDiv.parentNode) {
			parentDiv.removeChild(childDiv);
		}
	}
	onload()
</script>

</html>

这是需要引入的html页面

然后还需要一个js函数。这个函数,负责渲染生成dom节点

javascript 复制代码
function renderNode() {
   let calendar = document.createElement('div')
   calendar.className = 'calendar-box'
   return calendar
}

然后还要有样式文件

css 复制代码
.calendar-box{
    width: 400px;
    height: 400px;
    border: solid 1px red;
    background-color: gray;
    position: absolute;
    top: 50px;
    left: 50px;
}


/* #floating-div {
    position: absolute;
    top: 0;
    left: 0;
} */
复制代码
<link rel="stylesheet" href="./dialoge.css">
<script src="./dialoge.js"></script>

把生成的文件,在需要日历的页面引入即可。

相当于react中,有类组件和函数组件,这里就相当于函数组件,用函数生成的组件,就是函数生成的dom。这样理解就知道如何引入了。

相关推荐
156082072197 分钟前
银河麒麟 Qt 可执行文件打包说明
开发语言·驱动开发·qt
SEO_juper11 分钟前
手写 llms.txt 验证器:让 AI 更愿意引用你的网站(GEO)
开发语言·人工智能·python·聚类·seo·独立站
CCCCCCCCharlie11 分钟前
从0到1:一个字节的磁盘之旅
linux·开发语言·c++
比兔代理15 分钟前
纯净IP是什么?从IP信誉、黑名单与ASN角度原理解析
开发语言·php
benjiangliu25 分钟前
恩培趣味计算机视觉-01-conda环境和Python库
开发语言·python·conda
我喜欢就喜欢30 分钟前
DeepSeek Harness 开源贡献手记:从零到合入主线
开发语言·人工智能
坐看风云变幻35 分钟前
《嵌入式工程师的软硬件修仙之路》第 2 期|C 语言筑基:指针与内存模型
c语言·开发语言
王大师王文峰43 分钟前
HTML 入门到进阶:语义化标签、表单与多媒体一篇打通【语义化布局、表单校验、video/audio、Canvas、无障碍与 SEO】
前端·css·node.js·html·css3·jquery·html5
开开心心就好1 小时前
安卓PDF处理工具,免费无广告零弹窗
android·服务器·开发语言·算法·pdf·ocr
Pniubi1 小时前
HashMap扩容全流程
java·开发语言·数据结构