簡體   English   中英

innerHTML不更改div輸出

[英]innerHTML not changing div output

我試圖根據用戶單擊的單選按鈕顯示文本區域。 當注釋掉“競賽”功能時,新聞稿部分可以正常工作。 但是,當包含競賽功能時,新聞通訊將不起作用。 我嘗試調試,但是似乎找不到問題。 我嘗試使用不同的形式,但不會改變問題。

我的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> 

@jcubic提供的答案是錯誤。 關閉標簽可修復遇到的錯誤。

暫無
暫無

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

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