1.startsWith
1.1 个人理解
1.2 代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>startsWith</title>
<script>
let str = 'http://www.adsd.com/';
if (str.startsWith('http://')) {
alert('普通网址');
} else if (str.startsWith('https://')) {
alert('加密网址');
} else if (str.startsWith('git://')) {
alert('git网址');
}
</script>
</head>
<body>
</body>
</html>
2.endsWith
2.1 个人理解
2.2 代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>endsWith</title>
<script>
let str = '123313@qq.com';
if (str.endsWith('@qq.com')) {
alert('QQ邮箱');
} else if (str.endsWith('@163.com')) {
alert('网易云邮箱');
} else {
alert('其他邮箱');
}
</script>
</head>
<body>
</body>
</html>
3.字符串连接
3.1 个人理解
3.2 代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>字符模板化</title>
<script>
let title = "标题";
let content = "内容";
let strone = '<div>\
<h1>' + title + '</h1>\
<p>' + content + '</p>\
</div>';
alert(strone);
let strtwo = `<div>
<h1>${title}</h1>
<p>${content}</p>
</div>`
alert(strtwo);
</script>
</head>
<body>
</body>
</html>