這個問題在這里已經有了答案: 為什么我收到“ReferenceError: getElementById 未定義”? (1 個回答) 4 天前關閉。
由于某些原因,我無法使用 javascript 顯示 #coupon,當我嘗試獲取 elementById 時,它顯示錯誤訊息 elementById undefined,
HTML
<html>
<head>
<title>Exercise</title>
<link rel="stylesheet" href="stylesheet.css">
<script src="javascript.js"></script>
</head>
<body>
<div class="inputi">
<p class="input-text">Une Jam?</p> <input placeholder="Sheno emrin..." type="text" id="inputId">
//checks input value
<button type="button" onclick="getInputValue()">Vazhdo</button>
// shows error message if it doesn't match the array
<p id="message"></p>
</div>
// i want to display this with javascript, after the login
<h1 id="coupon">You won giftcard </strong></h1>
<button id="coupon">abas</button>
</body>
</html>
JS(問題)
** 問題getElementById 未定義,我想在成功登錄嘗試后顯示:阻止。**
var zzz = getElementById("coupon")
if(zzz === "none") {
display:block; }
// document.writeln("<h1>Keni fituar kupon 50% ne <strong> Green & Protein </strong> </h1>");
// document.writeln('<input class="giftcode" placeholder="' finalcode '" type="text" id="inputId">');
display_image(images[z], 400, 400, 'Javascript');
document.write('<br>' user[i]);
}
}
}
uj5u.com熱心網友回復:
兩件事情:
getElementById應該document.getElementById你需要將你的腳本標簽移動到標簽的底部,
body以確保當你選擇它時元素在 DOM 中
用:
<html>
<head>
<title>Exercise</title>
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<div class="inputi">
<p class="input-text">Une Jam?</p>
<input placeholder="Sheno emrin..." type="text" id="inputId">
//checks input value
<button type="button" onclick="getInputValue()">Vazhdo</button>
// shows error message if it doesn't match the array
<p id="message"></p>
</div>
// i want to display this with javascript, after the login
<h1 id="coupon">You won giftcard </h1>
<button id="coupon">abas</button>
<script src="javascript.js"></script>
</body>
</html>
uj5u.com熱心網友回復:
從上面的代碼可以看出,您正在嘗試呼叫尚未定義的方法 getElementById()。
第二,您只能在檔案中分配 1 個 ID,否則它將不起作用。
你可以做這樣的事情
// 我想在登錄后用 javascript 顯示這個
<span id="coupon" style="display: none">
<h1>You won giftcard </strong></h1>
<button>abas</button>
</span>
你想呼叫的是 document.getElementById("coupon"); 這是正確的功能。
所以試試這個;
var zzz = document.getElementById("coupon");
我真的不知道你成功登錄的標準是什么,但這個節目幫助讓你設定一個變數作為var success = "yes"成功登錄
if(success === "yes"){
zzz.style.display = "block";
}
uj5u.com熱心網友回復:
document.getElementById改為打電話。檔案 - https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById
uj5u.com熱心網友回復:
嘗試:document.getElementById 而不是:getElementById
因為 getElementById 是一個檔案方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/359554.html
標籤:javascript html css dom
