kk Blog —— 通用基础


date [-d @int|str] [+%s|"+%F %T"]
netstat -ltunp
sar -n DEV 1

form 提交前检查

https://www.cnblogs.com/min-yu/p/11187485.html

onsubmit只能表单上使用,提交表单前会触发, onclick是按钮等控件使用, 用来触发点击事件。

在提交表单前,一般都会进行数据验证,可以选择在submit按钮上的onclick中验证,也可以在onsubmit中验证。

但是onclick比onsubmit更早的被触发。

onsubmit处理函数返回false,onclick函数返回false,都不会引起表单提交。

onsubmit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<script language="javascript">
	function CheckPost()
	{
		if (addForm.user.value == "")
		{
			alert("请填写用户名!");
			addForm.username.focus();
			return false;
		}
		if (addForm.title.value.length < 5)
		{
			alert("标题不能少于5个字符!");
			addForm.title.focus();
			return false;
		}
		return true;
	}
</script>

<form action="test.php" method="post" name="addForm" onsubmit="return CheckPost();">
	<div>用户:<input type="text" size="10" name="user" maxlength="20"/></div>
	<div>标题:<input type="text" name="title" maxlength="50"/></div>
	<div>内容:<textarea name="content" rows="8" cols="30"></textarea></div>
	<div><input type="submit" name="submit" value="发表留言"/></div>
</form>

onclick

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<script language="javascript">
	function SendForm()
	{
		if(CheckPost())
		{
			document.addForm.submit();
		}
	}

	function CheckPost()
	{
		 if (addForm.user.value == "")
		 {
			 alert("请填写用户名!");
			 addForm.username.focus();
			 return false;
		 }
		 if (addForm.title.value.length < 5)
		 {
			 alert("标题不能少于5个字符!");
			 addForm.title.focus();
			 return false;
		 }
		 return true;
	}
</script>

<form action="test.php" method="post" name="addForm">
	<div>用户:<input type="text" size="10" name="user" maxlength="20"/></div>
	<div>标题:<input type="text" name="title" maxlength="50"/></div>
	<div>内容:<textarea name="content" rows="8" cols="30"></textarea></div>
	<div><input type="button" name="submit" value="发表留言" onclick="SendForm();"/></div>
</form>

CSS实现侧边栏导航 + 透明

https://www.cnblogs.com/liubingyjui/p/12698504.html

css background背景透明

1
2
background: transparent;
background: rgba(0, 0, 0, 0.8);

CSS实现侧边栏导航

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
		/*隐藏checked复选框*/
			#sidemenu{
				display: none;
			}

			#sidemenu:checked + aside {
				/*为被选中的sidemenu后的aside设置属性(紧邻)*/
				left: 0;
				/*点击按钮即选中checked后,侧边栏位置变为贴着左边,配合ease-out使用,有渐变滑出的效果*/
			}

			#sidemenu:checked ~ #wrap {
				/*为被选中的sidemenu后的wrap设置属性(非紧邻)*/
				padding-left: 220px;
			}

			aside {
				/*侧边栏,初始位置为-200px,即隐藏效果*/
				position: absolute;
				top: 0;
				bottom: 0;
				left: -200px;
				width: 200px;
				background: black;
				transition: 0.2s ease-out;
				/*动画效果的执行方式是ease-out,即侧边栏滑动效果为渐变式,而不是生硬的突然变化*/
			}

			h2 {
				color: white;
				text-align: center;
				font-size: 2em;
			}

			/*控制侧边栏进出的按钮(外部包裹)*/
			#wrap {
				margin-left: 20px;
				padding: 10px;
				transition: 0.2s ease-out;
			}

			/*控制侧边栏进出的按钮(内部文字样式)*/
			label {
				/*控制侧边栏进出的按钮*/
				background: white;
				border-radius: 70px;
				color: orange;
				cursor: pointer;
				display: block;
				font-family: Courier New;
				font-size: 2em;
				width: 1.5em;
				height: 1.5em;
				line-height: 1.5em;
				text-align: center;
				display: inline-block;
			}

			label:hover {
				background: #000;
			}

			#sideul li {
				list-style: none;
				color: white;
				width: 100%;
				height: 1.8em;
				font-size: 1.5em;
				text-align: center;
			}

			a {
				text-decoration: none;
			}

			#sideul li:hover {
				color: orange;
			}
		</style>
	</head>

	<body>
		<input type='checkbox' id='sidemenu'>
		<aside>
			<h2>主菜单</h2>
			<br />
			<ul id="sideul">
				<a href="##">
					<li>首页</li>
				</a>
				<a href="##">
					<li style="color: orange;">导航1</li>
				</a>
				<a href="##">
					<li>导航2</li>
				</a>
				<a href="##">
					<li>导航3</li>
				</a>
				<a href="##">
					<li>导航4</li>
				</a>
				<a href="##">
					<li>导航5</li>
				</a>
				<a href="##">
					<li>导航6ʳ</li>
				</a>
			</ul>
		</aside>
		<div id='wrap'>
			<label id='sideMenuControl' for='sidemenu'>≡</label>
			<!--for 属性规定 label 与哪个表单元素绑定,即将这个控制侧边栏进出的按钮与checkbox绑定-->
		</div>
	</body>
</html>

html实现点击直接下载文件

http://www.divcss5.com/html5/h57401.shtml

这样当用户打开浏览器点击链接的时候就会直接下载文件。

但是有个情况,比如txt,png,jpg等这些浏览器支持直接打开的文件是不会执行下载任务的,而是会直接打开文件,这个时候就需要给a标签添加一个属性“download”;

使用 a 标签

1
<a href="/user/test/xxxx.txt" download="文件名.txt">点击下载</a>