我有一个表格,上面有一些选项。我想根据单击的内容绘制一个新表单。 我是 Javascript 新手,所以我知道我做错了,但我似乎找不到正确的方法来做到这一点。 这是我的代码。
<form>
<input type="radio" name="postTo" id = "facebook" value="Facebook" checked="checked"/>Facebook
<input type="radio" name="postTo" id = "twitter" value="Twitter"/>Twitter
<input type="radio" name="postTo" id = "tumblr" value="Tumblr"/>Tumblr
<input type="radio" name="postTo" id = "instagram" value="Instagram"/>Instagram
</form>
<script>
if (content.getElementById('facebook').checked)
{
}
else if (content.getElementById('twitter').checked)
{
}
else if (content.getElementById('tumblr').checked)
{
<form name="newPostTumblr" action="" method="">
<h2>Tumblr</h2>
<p><label for="postTitle">Title:</label> <input type="text" id="postTitle" /></p>
<p><label for="postContent">Content:</label> <input type="text" id="postContent" /></p>
</form>
最佳答案
您使用了错误的语法,它必须是文档而不是内容..
替换
if (content.getElementById('facebook').checked)
与
if (document.getElementById('facebook').checked)
----^^^^^^^^
关于javascript - 选择单选按钮时绘制表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18799760/