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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值