设置显示为阻止时与子项一起出现问题

时间:2014-12-22 00:33:46

标签: javascript jquery css

我想在div(id = editor)显示块中创建所有div。但是,当我更改div(id = editor)显示时,只有div的显示被更改,div中的所有其他内容都显示为none。

这是我的编码:

doctype html
html
head
    title #{title} - My Site
    link(rel='stylesheet', href='stylesheets/style.css')
    script(src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js")
    script.
        function name(id, id2){
            document.getElementById(id).style.display = 'block';
            document.getElementById(id2).style.display = 'none';
            //document.getElementById(id3).style.display = 'none';
            }
body(onload ='name("rename", "ineditortxt")')
    div(id="rename", class="Name")
    h1= "Enter File Name"
    form(id = "filename", method ="post")
        input(id="new_name", type ="text", placeholder="File Name")
        input(id="Okay", type="submit", value="Okay")

div(id="ineditortxt")
    h1= "Welcome to Editor"
    div(id="editor")
        |Welcome to the home pages
        |This is the first Paragraph
    script(src="javascripts/ace.js", type="text/javascript")
    script.
            var editor=ace.edit("editor");
    script(src="/jvm.js", type="text/javascript")
script.
    document.getElementById('filename').addEventListener('submit',function(e){
        e.preventDefault();
        document.getElementById("ineditortxt").style.display = 'block';
        document.getElementById("editor").style.display='block';
        document.getElementById("rename").style.display = 'none';
    });

enter image description here

1 个答案:

答案 0 :(得分:1)

我不知道您帖子中的语言是什么,但由于您的问题标记为" jquery",jQuery要执行您正在描述的内容:

$("#editor, #editor div").css("display", "block");

没有jQuery,它将是:

var editor = document.getElementById("editor");
editor.style.display = "block";

var insideDivs = editor.getElementsByTagName("div");
for (var i = 0; i < insideDivs.length; i += 1) {
    insideDivs.style.display = "block";
}