用原生js实现点击单元格输出单元格中的值转换成百分比(保留两位小数)和该单元格对应的表头,如'同花顺:3.30%'

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<table border="1px">
		<thead>
			<tr>
				<th>
					股票名称
				</th>
				<th>
					涨跌幅
				</th>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td>同花顺</td>
				<td>0.033</td>
			</tr>
			<tr>
				<td>同花</td>
				<td>0.034</td>
			</tr>
			<tr>
				<td>同顺</td>
				<td>0.023</td>
			</tr>
			<tr>
				<td>花</td>
				<td>0.038</td>
			</tr>
			<tr>
				<td>顺</td>
				<td>0.013</td>
			</tr>
			<tr>
				<td>同</td>
				<td>0.031</td>
			</tr>
		</tbody>
	</table>
</body>
<script type="text/javascript">
	var tr = document.getElementsByTagName('tr')
	var trr = [...tr]
	trr.shift()
	console.log(trr)
	trr.map(item=>{
		item.onclick = ()=>{
			console.log(item.children[0].innerHTML + ':' +(item.children[1].innerHTML * 100).toFixed(2) + '%')
		}
	})
</script>
</html>
posted @ 2020-04-01 14:24  海常7号  阅读(463)  评论(0编辑  收藏  举报