【问题标题】:how can i show a Div and hide a form once the form has been submitted? i've tried jquery but it doesnt work. help me?提交表单后,如何显示 Div 并隐藏表单?我试过jquery,但它不起作用。帮我?
【发布时间】:2014-03-29 18:13:42
【问题描述】:

提交表单后,如何显示 Div 并隐藏表单?我试过jquery,但它不起作用。帮我?这是代码:

网站 身体 {
背景颜色:黑色; 颜色:绿色; }

#theirname {
  color:red;
  font-size: 6.0em;
  margin:auto;
  text-align:center;
  display:none;
}

#hellos {
  color:yellow;
  font-size:6.5em;
  margin-top:auto;
  text-align:left;
  display:none;
}
#thanks {
  color:yellow;
  font-size:4.3em;
  margin-right:20px;
  text-align:right;
  display:none;
}

#hello { 
  border-style:groove; 
  border-color: yellow; 
  margin:auto;
  text-align:center;
  width:300px;
}

marquee {
  color:yellow;
  font-size:30px;
}
form {
  text-align:center;
  margin:auto;
  margin-top:120px;
}
</style>
<script>
function handler() {
  var div = document.getElementById('theirname');

  var form = document.getElementById('fore');

     div.innerHTML = document.getElementById('textbox').value;
     return false;
}

$(document).ready(function(){
  $("#Fore").submit(function(e){
    $("#fore").hide(slow);
  $("#hellos").show(3000);
  $("#theirname").show(3030);
  $("#thanks").show(4000);
  });
});

</script>
</head>

<body>
<div id="hello">Welcome to here :D</div>

<marquee behavior="scroll" scroll="left" bgcolor="red" onClick="">ill update this soon...</marquee>

<div id="hellos">Hello,</div>
<div id="theirname"></div>
<div id="thanks">thank you for coming!</div>

<form id="Fore" action="submit" method="post" onSubmit="return handler();">
Your name: <input id="textbox" type="text" name="fname" size="20" />
<input type="submit" value="post" />
</form>


</body>
</html>

这里是为了让你明白我的意思。 jfiddle

【问题讨论】:

  • 选框+50...
  • 什么意思?大声笑

标签: jquery html css forms submit


【解决方案1】:

您的 javascript 中有错误:

改变

$("#fore").hide(slow);

$("#Fore").hide('slow'); //  Your id is Fore and not fore

【讨论】:

  • 我刚刚更新了我的代码以及jsfiddle,但它仍然不起作用。
  • 删除
  • 成功了! @A.沃尔夫! :D 你知道我的代码有什么问题吗?请告诉我,我正在努力学习。 :)
  • 首先您的 id 与表单 id 不同 ('fore' -> 'Fore') 其次,当调用慢速隐藏函数时,您需要添加撇号('slow')“It works”通常是通过接受问题在 Stack Overflow 上表达 =p
  • @Mrawesome4ever 我不是回答者... ;) 你的 jsFiddle 需要包含 jQuery,所有其他错误都在这个答案中解释。作为一个好建议,始终使用控制台进行调试以检查任何错误(Windows 浏览器中的 f12)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-02
  • 1970-01-01
  • 2017-08-02
  • 2017-08-30
  • 1970-01-01
  • 2021-08-31
  • 2014-11-24
相关资源
最近更新 更多