平常小工具函数合集

拷贝文案

copyText(text = '') {
		const input = document.createElement('input');
		// 改为只读,禁止用户输入法自动获取焦点(兼容 IOS)
		input.setAttribute('readonly', 'readonly');
        input.setAttribute('value', text);
		document.body.appendChild(input);
		// 人为的设置选中所有文案(兼容 ios)
		input.select();
		input.setSelectionRange(0, 9999);
		const copyResValue = document.execCommand('copy');
		// 清除元素
        document.body.removeChild(input);
		return copyResValue;
	},
复制代码
相关文章
相关标签/搜索