javascript文件變量同名有時會帶來變量覆蓋的問題,如如下代碼:
same.html:javascript
<!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.jshtml
var result="";