Javascript 我能';在html中不显示节
我有一个隐藏的部分Javascript 我能';在html中不显示节,javascript,html,css,Javascript,Html,Css,我有一个隐藏的部分(“secundaria”),我想用js从该部分之外的一个位置显示它。本节及其css为: <section id="secundaria"> <!--Formulario 2--> <h3>Nuevo pedido</h3> <form id="formulario_secundario"> Nombre: &l
(“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>
我想用这个函数从这个表单中显示它:
<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>
环境:
函数新公式(){
log(document.getElementById(“secundaria”).style.visibility);
document.getElementById(“secundaria”).style.visibility=“可见”;
log(document.getElementById(“secundaria”).style.visibility);
document.getElementById(“新表单”).reset();
}
这是为了上课,所以我的老师希望函数和部分在另一个部分内,形式在外部。谢谢。您的代码工作正常。问题是
submit
类型的input
会隐式发送表单,导致页面重新加载。切换到type=“button”
,一切正常
函数新公式(){
log(document.getElementById(“secundaria”).style.visibility);
document.getElementById(“secundaria”).style.visibility=“可见”;
log(document.getElementById(“secundaria”).style.visibility);
document.getElementById(“新表单”).reset();
}
#secundaria{
可见性:隐藏;
}
新佩迪多
名义:
Fecha de cierre:
环境:
检查这把小提琴:
只需更改输入
input type=“button”
尝试使用type=“button”而不是新表单中的“submit”,或者使用返回false代码>在该函数中。@BhojendraNepal还有其他选项,但我认为最好的方法是更改按钮类型。因此,我使用了或语句。
<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>