javascript文件变量同名有时会带来变量覆盖的问题,如以下代码:
same.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h2 style="text-align: center">变量函数同名带来问题</h2>
<div style="text-align: center" id="output"></div>
<!--此javascript加载顺序,将会影响网页功能是否正确-->
<script src="sameName.js"></script>
<script>
var result=document.getElementById(‘output‘);
setInterval(function () {
result.innerHTML=new Date().valueOf();
},1000)
</script>
<!--<script src="sameName.js"></script>-->
</body>
</html>
sameName.js
var result="";