gpt4 book ai didi

javascript - innerHTML 不改变 div 输出

转载 作者:行者123 更新时间:2023-12-01 01:33:12 24 4
gpt4 key购买 nike

我试图根据用户单击的单选按钮来显示文本区域。当“竞赛”功能被注释掉时,时事通讯部分可以正常工作。但是当包含竞赛功能时,时事通讯就不起作用了。我尝试过调试,但似乎找不到问题。我尝试过使用不同的形式,但它并没有改变问题。

我的 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 提供的答案是错误。关闭标签修复了遇到的错误。

关于javascript - innerHTML 不改变 div 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53065031/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com