[英]HTML isn't working with javascript
我是編程新手。 我試圖在html中調用一個函數,但它不起作用。 有什么問題? 提前致謝。 (不要問整個整合的事情)。
我的HTML代碼:
<!DOCTYPE html>
<html>
<head>
<script src="IntegrationCalculator.js"></script>
<script>
integrationCalculator(7);
</script>
</head>
<body>
<p id="tester">
Didn't work :(
</p>
</body>
我的javascript代碼:
var integrationCalculator = function (variable1) {
if (variable1 = 7) {
document.getElementById("tester").innerHTML="WORKED";
}
};
兩件事情。 首先if (variable1 = 7)
應該是if (variable1 == 7)
。 其次,在元素加載到DOM后調用您的函數。
<!DOCTYPE html>
<html>
<head>
<script src="IntegrationCalculator.js"></script>
</head>
<body>
<p id="tester">
Didn't work :(
</p>
<script>
integrationCalculator(7);
</script>
</body>
在創建tester
段落之前調用integrationCalculator
。 因此,拋出錯誤並停止執行腳本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.