我可以't在html中显示部分
I can't show section in html
我有一个隐藏的节("secundaria")
,我想用js从节外显示它。该节及其css为:
<section id="secundaria">
<!--Formulario 2-->
<h3>Nuevo pedido</h3>
<form id="formulario_secundario">
Nombre:
<input type="text" name="Nombre" value="" />
<br/>
Fecha de cierre:
<input type="text" name="Fecha_cierre" value="" />
<br/>
<input type="submit" value="Aceptar" name="aceptar" onclick="validar_rellenar(this.form)" />
<br/>
<input type="submit" value="Cancelar" name="cancelar">
</form>
</section>
及其css:
section#secundaria{
visibility:hidden;
}
我想用这个功能从这个表格中显示它:
<form id="nuevo_form">
Envio:
<input type="text" name="envio" value="" />
<br/>
<input type="submit" id="nuevo" value="" onclick = "nuevo_formulario()">
</form>
<script>
function nuevo_formulario(){
console.log(document.getElementById("secundaria").style.visibility);
document.getElementById("secundaria").style.visibility = "visible";
console.log(document.getElementById("secundaria").style.visibility);
document.getElementById("nuevo_form").reset();
}
</script>
这是为了上课,所以我的老师希望函数和部分在另一个部分里,形式在外面。谢谢
您的代码工作正常。问题是submit
类型的input
将隐式发送表单,从而导致页面重新加载。更改为type="button"
,一切正常。
function nuevo_formulario() {
console.log(document.getElementById("secundaria").style.visibility);
document.getElementById("secundaria").style.visibility = "visible";
console.log(document.getElementById("secundaria").style.visibility);
document.getElementById("nuevo_form").reset();
}
#secundaria {
visibility: hidden;
}
<section id="secundaria">
<!--Formulario 2-->
<h3>Nuevo pedido</h3>
<form id="formulario_secundario">
Nombre:
<input type="text" name="Nombre" value="" />
<br/>Fecha de cierre:
<input type="text" name="Fecha_cierre" value="" />
<br/>
<input type="submit" value="Aceptar" name="aceptar" onclick="validar_rellenar(this.form)" />
<br/>
<input type="submit" value="Cancelar" name="cancelar">
</form>
</section>
<form id="nuevo_form">
Envio:
<input type="text" name="envio" value="" />
<br/>
<input type="button" id="nuevo" value="" onclick="nuevo_formulario()">
</form>
检查这个小提琴:https://jsfiddle.net/zjwon1sy/
只需更改输入input type="button"
相关文章:
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 使用鼠标悬停JavaScript/HTML显示文本
- 用javascript在html显示列表中显示新成员
- 尊重“; 〃;从HTML显示中的API响应返回的换行符(和特殊字符)
- HTML 显示/隐藏元素 JS 不起作用
- 从一个文本框执行代码,并在另一个文本框中以 HTML 显示输出
- 使用javascript for html显示特定时区的日期和时间
- 如何将一个元素的外部HTML显示为另一个元素的内容
- 将SQL BIT转换为JSON,直到jQuery,最后以HTML显示
- 使用 Javascript 迭代以 HTML 显示多个图像
- 文本(输入)字段中的 HTML 显示结果
- PHP - 作曲家自动加载器导致 html 显示在浏览器中
- 将HTML文件中的表单提交到PHP文件,并以相同的HTML显示结果
- 如何使 HTML/Javascript 从 PHP 脚本接收数据并以 HTML 显示
- 显示一个图像,然后使用 HTML 显示另一个图像
- input type=“password” 在 IE 11 上使用 HTML 5 显示文本
- 使用 JSON 从 PHP 返回数组并以 HTML 显示内容的适当方法
- Jquery对话框IE9内容未使用html显示
- HTML显示在“;查看源“;与Firebug中显示的HTML不同
- 使用jQuery.HTML()插入时HTML显示不正确