当前位置:   article > 正文

html中字符串的获取方法_获取html字符串标签内容的方法

获取html字符串标签内容的方法

html中字符串的获取几种方法

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style >
		.layout{
			position: absolute;
			top: 0;
			width: 100%;
			height: 100%;
			background-color: rgba(0,0,0,0.2);
		}
		.layout .loginModel{
			width:360px;
			padding-bottom: 30px;
			margin: 200px auto 0;
			background-color: #fff;
		}
		.close{
			float: right;
			margin-right: 18px;
			margin-top: 12px;
			width: 16px;
			height: 16px;
			border: 1px solid #000;
			background-image:url(image/pass_login_icons.png);
			background-repeat: no-repeat;
			background-position: -55px -48px;
			cursor: pointer;     //小手现状
		}
		.close:hover{
			background-position: -71px -48px;
		}
		.loginTitle{
			margin-left: 117px;
			display: inline-block;
			margin-top: 10px;
		}
		.loginModel input{
			width: 300px;
			height: 40px;
			display: block;
			margin: 18px auto 0;

		}
		#loginbtn{
			border: none;
			width: 300px;
			height: 40px;
			display: block;
			margin: 18px auto 0;
			background-color: #3F89EC;
			color: #fff;
			font-size: 16px bold;
		}
	</style>
</head>
<body>
<a href="javascript:;" id="btn">登录</a>
	<div class="layout">
		<div class="loginModel">
			<p><span class="loginTitle">用户名通行证登录</span><span class="close"></span></p>
			<input type="text" id="username" placeholder="访客名:输入游客">
			<input type="password" id="userpwd" placeholder="通行码:8848">
			<button id="loginbtn">进入</button>
		</div>
	</div>
</body>
<script>
	// 组成字符串+字符串的拼接
	
	var loginbtn = document.getElementById('loginbtn')
	var username = document.getElementById('username')
	var userpwd = document.getElementById('userpwd')
	loginbtn.onclick = function(){
		var username_val = username.value
		var userpwd_val = userpwd.value
		var str = ''
		str = 'username =' +username_val+'&'+'userpwd='+userpwd_val
		console.log(str)
	}
	
	//字符串的截取 1:通过下标的方法
	var cookie = "hfhsfhsfhshHUIHHHHuhhghgihdHUHHUYGUHIhhf;shush=sfsdgsgsbsbsbsufus;"
	/*
	var Oindex = cookie.indexOf('shush')
	var firstindex = Oindex+'shush'.length+1
	var secondindex = cookie.indexOf(';',firstindex)
	console.log(firstindex,secondindex)
	var val = cookie.slice(firstindex,secondindex)
	console.log(val)
	*/
	// 2:字符串的分割
	var arr = cookie.split(';')
	console.log(arr)
	for (var i = 0;i<arr.length; i++) {
		var arr2 = arr[i].split('=')
		if (arr2[0].trim() =='shush') {
			console.log(arr2[1])
		}
	}
	// 电话号码的隐藏 1:截取
	var phonenumble = '13355666208'
	/*
	var newphonenumble = phonenumble.slice(0,3)+'****'+phonenumble.slice(7)
	console.log(newphonenumble)
	*/
	// 2:替换
	var newphonenumble2 = phonenumble.replace(/^(\d{3})\d{4}(\d+)/,'$1****$2')
	console.log(newphonenumble2)
</script>
</html>

  • 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/92925?site
推荐阅读
相关标签
  

闽ICP备14008679号