Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我能';在html中不显示节_Javascript_Html_Css - Fatal编程技术网

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>