前端模板(测试使用)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-------------------------------------------插件开始------------------------------------------->
<!-- jQuery 这边是我自己的jQuery目录-->
<script type="text/javascript" src="js/jquery-3.4.1/jquery-3.4.1.js" ></script>
<script type="text/javascript" src="js/jquery-3.4.1/jquery-3.4.1.min.js" ></script>
<!-- 自定义 -->
<!-------------------------------------------插件结束------------------------------------------->
<title>测试页面</title>
<script>
MsgDiv = document.getElementById("codeDiv");
window.onload = function(){
MsgDiv.innerHTML += "客户端:开启测试页面<br/>";
}
</script>
</head>
<body>
<button onclick="deleteTheMsgDiv();" style="margin-top: 10px">删除记录</button>
<div id="codeDiv" style="width: 100%; height: 500px;border: solid black 1px;margin-top: 10px;">
</div>
<script>
MsgDiv = document.getElementById("codeDiv");
function deleteTheMsgDiv() {
console.log("删除记录")
MsgDiv.innerHTML = "";
}
</script>
</body>
</html>
执行页面
代码分析
一、设置一个div作为打印记录的位置
<div id="codeDiv" style="width: 100%; height: 500px;border: solid black 1px;margin-top: 10px;">
二、通过id获取div的内容
MsgDiv = document.getElementById("codeDiv");
三、清空div打印内容
<button onclick="deleteTheMsgDiv();" style="margin-top: 10px">删除记录</button>
<script>
MsgDiv = document.getElementById("codeDiv");
function deleteTheMsgDiv() {
console.log("删除记录")
MsgDiv.innerHTML = "";
}
</script>
四、页面的进入判断以及div功能测试
<script>
MsgDiv = document.getElementById("codeDiv");
/* window.onload 该函数用于进入页面的时候使用 */
window.onload = function(){
MsgDiv.innerHTML += "客户端:开启测试页面<br/>";
}
</script>