angularJS-实现文本框的复制功能

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36898102/article/details/78715996
<!DOCTYPE html>
<html ng-app="myPro">
	<head>
		<meta charset="UTF-8">
		<title>angularJS-实现文本框的复制功能</title>
		<script type="text/javascript" src="js/jquery-1.7.2.min.js" ></script>
		<script type="text/javascript" src="js/angular.min.js" ></script>
		<style>
			*{margin: 0;padding: 0;}
			ol,ul{list-style: none;}
			.box{width: 500px;height:150px;border: 1px solid gray;margin: 100px auto;padding-top: 20px;}
			.box input{width: 200px;height: 30px;height: 30px;}
			.box textarea{margin: 20px 0 0 20px;}
		</style>
	</head>
	<body ng-controller = "myProController">
		<div class="box">
			文本框:<input type="text" id="text"/>
			<button ng-click="copyText()">复制</button>
			<textarea  rows="4" cols="50"></textarea>
		</div>
	</body>
	<script>
		var pro  = angular.module("myPro",[]);
		pro.controller("myProController",["$scope",function($scope){
			//点击复制文本框内容
			$scope.copyText = function(evt) {
			  	var Url1=document.getElementById("text"); 
			  	console.log(Url1.value);
			  	Url1.select(); //选择对象  
			  	var tag = document.execCommand("Copy"); //执行浏览器复制命令  
			  	if(tag){
			  		alert("复制成功。")
			  	};
			};			
		}]);
	</script>
</html>

没有更多推荐了,返回首页