javascript - innerHTML 不改变 div 输出
问题描述
我正在尝试根据用户单击的单选按钮显示文本区域。当“竞赛”功能被注释掉时,时事通讯部分工作正常。但是当包含竞赛功能时,时事通讯不起作用。我试过调试,但似乎找不到问题。我尝试过使用不同的形式,但这并没有改变问题。
我的 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 提供的答案是错误。关闭标签修复了遇到的错误。
推荐阅读
- python - 在 Python Pandas 中,如何创建此表,与前一行在同一列中的新行并从其他列添加同一行?
- hash - Puppet:合并具有相同键的哈希
- java - 用自定义注解继承@PreAuthorize注解,用于spring自定义方法安全表达式
- mongodb - 通过数组映射时将值解析为字段
- ios - MPEG4 视频无法在 iOS14 上播放(AVPlayer 问题)
- html - 无法制作 svg 图像半页
- c# - 在 Xamarin Android 中使用 Refit 发送 PDF 文件
- palantir-foundry - 如何使 Foundry Slate 容器可折叠?
- cumulative-sum - 快速累积和?
- html - 如何使用 CSS 在 HTML 页面中对齐 GitHub Gist?