简体   繁体   English

innerHTML不更改div输出

[英]innerHTML not changing div output

I'm trying to display a text area depending on what radio button the user clicks. 我试图根据用户单击的单选按钮显示文本区域。 When the "contest" function is commented out, the newsletter part works fine. 当注释掉“竞赛”功能时,新闻稿部分可以正常工作。 But when the contest function is included, the newsletter does not work. 但是,当包含竞赛功能时,新闻通讯将不起作用。 I've tried debugging but I can't seem to find an issue. 我尝试调试,但是似乎找不到问题。 I've tried using different forms but it doesn't change the problem. 我尝试使用不同的形式,但不会改变问题。

My HTML: 我的HTML:

 function newsletter() { var response = ""; if(document.getElementById("yes").checked) { response += "<p><b>Enter Your Address:</b></p>"; response += '<input type="text" id="address"><br>'; var output = document.getElementById("isChecked"); output.innerHTML = response; } } function contest() { var resp = ""; if(document.getElementById("answer").value == "Y") { resp += "<p><b>Enter your credit card information to verify age ($0.00 charge)</b></p>"; resp += "<br>"; resp += '<input type="text" id="first4" size="4" maxlength="4">'; resp += "-"; resp += '<input type="text" id="second4" size="4" maxlength="4">'; resp += "-"; resp += '<input type="text" id="third4" size="4" maxlength="4">'; resp += "-"; resp += '<input type="text" id="fourth4" size="4" maxlength="4"'; var out = document.getElementById("contestOutput"); out.innerHTML = resp; } } 
 body {background-color: pink; } 
  <center> <h1>Magnificant Music!</h1> </center> <p>Welcome Blue Note Records visitors! On this site, you can enter your information to recieve a card sent every month informing you about the lastest releases on your favorite record label, and a chance to enter a contest that could win you a brand new instrument of your choice!</p> <form action="" method="post"> <fieldset> <p><b>Personal Information</b></p> <label>First Name:</label> <input type="text" id="firstName"><br> <label>Last Name:</label> <input type="text" id="lastName"><br> <label>Middle Initial</label> <input type="text" id="middleInit"><br> </fieldset> <br> <fieldset> <p><b>Do you want to recieve a newsletter?</b></p> <input type="radio" name="news" id="yes">Yes<br> <input type="radio" name="news" id="no">No<br> <button type="button" onclick="newsletter();">Submit</button> <div id="isChecked"></div> </fieldset> <br> <fieldset> <p><b>Would you like to enter the contest for a brand new instrument of your choice (Y / N)? (18 yrs old minimum)</b></p> <input type="text" size="1" id="answer"><br> <button type="button" onclick="contest();">Submit</button> <div id="contestOutput"></div> </fieldset> </form> 

The answer, provided by @jcubic, was the error. @jcubic提供的答案是错误。 Closing the tag fixed the error encountered. 关闭标签可修复遇到的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM