[英]Can someone find error in my code where I am working on how to inject js function in html
I am trying to inject js variable with html page.我正在尝试使用 html 页面注入 js 变量。 Here, I need to show givenname as "shelly" on my html page.
在这里,我需要在我的 html 页面上将给定名称显示为“shelly”。 But I am not getting result from this.
但我没有得到结果。 I used
我用了
Hello, id="givenname" .
你好, id="givenname" 。 Let's begin.
让我们开始。
<.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>
simply that?就这么简单?
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.