HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!DOCTYPE html>
<html>
<head>
<title>8_常用注册页面的表单实例(含验证).html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<style type="text/css">
body {
/*background-image: url(https://imgchr.com/content/images/system/home_cover_1552414407320_3a5f92.jpg);*/
background-image: url('https://cdn.jsdelivr.net/gh/yansheng836/photos/universe.jpg');
/*https://imgchr.com/content/images/system/home_cover_1587121321656_fce672.jpg
https://imgtu.com/content/images/system/home_cover_1601010270144_8921bc.jpg
https://cdn.jsdelivr.net/gh/yansheng836/photos/universe.jpg
*/
background-repeat: no-repeat;
/* 当内容高度大于图片高度时,背景图像的位置相对于viewport固定 */
background-attachment: fixed;
/*此条属性必须设置否则可能无效*/
/* 让背景图基于容器大小伸缩 */
background-size: cover;
/* 设置背景颜色,背景图加载过程中会显示背景色 */
background-color: #CCCCCC;
}
#user_reg {
font-family: 微软雅黑;
font-size: 40px;
text-align: center;
margin-top: 200px;
}
form {
width: 500px;
/*设置宽度,方便使其居中*/
margin: 40px auto auto auto;
/*上右下左*/
font-size: 25px;
}
input {
height: 30px;
width: 12em;
margin-top: 5px;
margin-bottom: 5px;
}
/*input标签下的属性选择器*/
input[type="submit"],
input[type="reset"] {
height: 25px;
width: 5em;
margin-top: 5px;
margin-left: 6px;
}
</style>
</head>
<script type="text/javascript">
//onblur失去焦点事件,用户离开输入框时执行 JavaScript 代码:
//函数1:验证邮箱格式
function validate_username(username) {
//定义正则表达式的变量:邮箱正则
var emailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
//console.log(username);
if (username != "" && username.search(emailReg) != -1) {
document.getElementById("test_user").innerHTML = "<font color='green' size='3px'>√邮箱格式正确</font>";
} else {
document.getElementById("test_user").innerHTML = "<font color='red' size='3px'>邮箱格式错误</font>";
}
}
//函数2:验证密码是否符合要求:匹配6位密码,由数字和字母组成:
function validate_password(password) {
//^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6-10}$
//测试密码:12345y
var passwordReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6}$/;
if (password != "" && password.search(passwordReg) != -1) {
document.getElementById("test_pw").innerHTML = "<font color='green' size='3px'>√密码格式正确</font>";
} else {
document.getElementById("test_pw").innerHTML = "<font color='red' size='3px'>密码格式错误</font>";
alert("密码有6位,由数字和字母组成!");
}
}
//函数3:验证两次输入的密码是否一样
function validate_password2(password2) {
var password = document.getElementById("password").value;
//测试:console.log(password);
//测试:console.log(password2);
if (password == "") {
document.getElementById("is_test_pw").innerHTML = "<font color='red' size='3px'>密码不为空</font>";
} else if (password == password2) {
document.getElementById("is_test_pw").innerHTML = "<font color='green' size='3px'>√两次输入的密码相同</font>";
} else {
document.getElementById("is_test_pw").innerHTML = "<font color='red' size='3px'>两次输入的密码不相同</font>";
console.log("密码有6位,由数字和字母组成!");
}
}
//函数4:验证表单是否已经填好
function validate_form() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var password2 = document.getElementById("password2").value;
//console.log("表单填写正确,可以正常提交!");
//这三个,如果任何一个有问题,都返回false
//[email protected] 12345y
var emailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
var passwordReg = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6}$/;
if (username != "" && emailReg.test(username)) {
if (password != "" && passwordReg.test(password)) {
if (password2 == password) {
alert("信息填写正确,可以正常提交!");
console.log("信息填写正确,可以正常提交!");
return true;
} else {
alert("密码不一致,提交失败,请重新填写!");
console.log("密码不一致,提交失败,请重新填写!");
return false;
}
} else {
alert("密码格式错误,提交失败,请重新填写!");
console.log("密码格式错误,提交失败,请重新填写!");
return false;
}
} else {
alert("注册的账号不符合要求,提交失败,请重新填写!");
console.log("注册的账号不符合要求,提交失败,请重新填写!");
return false;
}
}
</script>
<body>
<div id="user_reg">用户注册:</div>
<form action="./servlet/RegisterServlet" method="post" name="form">
<table>
<tr>
<td>请输入账号:</td>
<td><input type="text" id="username" name="username" placeholder="只能用邮箱注册" onblur="validate_username(this.value)" /></td>
<td id="test_user"></td>
</tr>
<tr>
<td>请输入密码:</td>
<td><input type="password" id="password" name="password" placeholder="6位密码由数字和字母组成" onblur="validate_password(this.value)" /></td>
<td id="test_pw"></td>
</tr>
<tr>
<td>请确认密码:</td>
<td><input type="password" id="password2" name="password2" onblur="validate_password2(this.value)" /></td>
<td id="is_test_pw"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" id="submit_form" value="注册" onclick="return validate_form()" />
<input type="reset" value="重置" />
</td>
</tr>
</table>
</form>
</body>
</html>
Also see: Tab Triggers