textarea 实现关键字变色

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<div>
		<style type="text/css">
			.in, .out {
				padding: 0;
				margin: 0;
				position: absolute;
				border: 1px solid #ccc;
				width: 350px;
				height: 100px;
				left: 10px;
				top: 10px;
				font-size: 14px;
				z-index: 3;
			}
			.in {
				outline: none;
				z-index: 2;
				color: black !important; 
				text-shadow: 0px 0px 0px #fff;
				 -webkit-text-fill-color: transparent;
			}
			.out {
				background-color: transparent;: 
			}
		</style>
		<textarea class="in" id='inaa' oninput='inputFunc()' style="width: 350px; height: 100px;"></textarea>
		<div id='put' class="out" onclick='inaa.focus()'>
		</div>
		<script type="text/javascript">
			function inputFunc (value) {
			 put.innerHTML = inaa.value.replace(/哈哈/g, '<span style="color: red;">哈哈</span>').replace(/嘿嘿/g, '<span style="color: orange;">嘿嘿</span>').replace(/绿色/g, '<span style="color: green;">绿色</span>').replace(/绿色/g, '<span style="color: green;">绿色</span>').replace(/红色/g, '<span style="color: red;">红色</span>').replace(/蓝色/g, '<span style="color: aqua;">蓝色</span>')
			}
		</script>
	</div>
</body>
</html>

大体就是这样 先贴上代码

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值