【发布时间】:2019-04-18 10:03:57
【问题描述】:
所以这就像我第一天编写 javascript 代码“因为我的意思是在我的 html 中实现它们”我只是有点卡住了几个小时来做这个
所以基本上我只有下面这样的注册表单
<div id="selaccount">
<select id = "accounttype"
<option id = "typeA">Firstname</option>
<option id = "typeB">Lastname</option>
<option id = "typeC">Email<option>
</select>
</div>
<div id="regform">
<div id="formA">
<input type = "text" placeholder = "Firstname">
</div>
<div id="formB">
<input type = "text" placeholder = "Lastname">
</div>
<div id="formC">
<input type = "Text" placeholder = "Email">
</div>
</div>
</body>
<script src ="main.js"> </script>
</html>
在我的 main.js 文件中,我一直在尝试写下这段代码:
function optionselect() {
var A = document.getElementById("selaccount");
var selected = A.SelectedIndex;
if (selected = document.getElementById("typeA"){
$("#formA").appendTo("#regform");}
else if (selected = document.getElementById("typeB){
$("formB).appendTo("#regorm");}
}
而且它只是没有显示任何东西,即使 vscode 也无法向我显示调试器,无论如何感谢您的任何回复,我真的很感激 抱歉英语不好
【问题讨论】:
-
首先。你那里有很多错别字。第二 - 不要混合使用 jquery 和 vanilla js。
-
你想达到什么目标?
-
嗨@sukehiro。你想干什么??
-
@Smollet777 实际上我只是想在选择选择时进行 regform 切换
-
@Smollet777 呃抱歉我不知道 javascript 不能这样做
标签: javascript html select append options