簡體   English   中英

有人可以在我正在研究如何在 html 中注入 js function 的代碼中找到錯誤嗎

[英]Can someone find error in my code where I am working on how to inject js function in html

我正在嘗試使用 html 頁面注入 js 變量。 在這里,我需要在我的 html 頁面上將給定名稱顯示為“shelly”。 但我沒有得到結果。 我用了

你好, id="givenname" 讓我們開始。

將 id 設為“givenname”。 在 js 腳本代碼中,我設置了 inner,html 以獲取名稱“shelly”。 js 的代碼為 document.getElementById("givenname").innerHTML="shelly"; 有人可以找到此代碼的問題所在。

 <.DOCTYPE html> <html lang="en"> <head> <title> Prectical2</title> <link href="styles2/style1,css" type="text/css" rel="stylesheet" /> </head> <body id="body"> <div id="content1"> <p>Hello. <b>id=givenname</b>. Let's begin?</p> </br> <div id="quiz"> <div id="N">Question N</div> <p>Question text should appear here</p> <div class="radio1"> <input type="radio" name="choices" id="A" value="A" /> <label for="A" id="choice-A">Choice A</label> </div> </br> <div class="radio2"> <input type="radio" name="choices" id="B" value="B" /> <label for="B" id="choice-B">Choice B</label> </div> </br> <div class="radio3"> <input type="radio" name="choices" id="C" value="C" /> <label for="C" id="choice-C">Choice C</label> </div> <div id="results"> <p>Your final score was.</p> </div> <div id ="quizsubmit"> <input type="button" value="Next" /> </div> </div> </div> </body> <script src="scripts/my-script.js" src="scripts/provided-script.js"> //alert(sucess) let fname="Shelly" document.getElementById("givenname");innerHTML = "fname"; </script> </html>

就這么簡單?

 let fname = 'Shelly'; document.querySelector('#givenname').textContent = fname;
 <p>Hello, <b id="givenname"></b>. Let's begin.</p>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM