点击li时如何在alert中显示li的内容
点击li时如何在alert中显示li的内容
点击li时如何在alert中显示li的内容
2018-10-02
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<ul>
<li>这是网页1</li>
<li>这是网页2</li>
<li>这是网页3</li>
</ul>
</body>
<script type="text/javascript">
var te = document.getElementsByTagName('li');
for(let i=0;i<te.length;i++)
{
te[i].onclick=function()
{
console.log(te[i].textContent);
alert(this.firstChild.nodeValue);
}
}
</script>
</html>
举报