简体   繁体   中英

javascript function not working in node.js Jade express

This is my code:

extends layout

block content
    h1= title
    div(id="rename", class="Name", onload='name("rename", "editor")')
        form(id = "filename", method ="post")
            input(id="new_name", type ="text", placeholder="File Name")
            input(id="Okay", type="submit", value="Okay")
    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.
        function name(id, id2){
            document.getElementById(id).style.display = 'block';
            document.getElementById(id2).style.display = 'none';
            //document.getElementById(id3).style.display = 'none';
            }

When I run it on the web, my javascript function is not being called. I can't seem to figure out why, however I think it has to do with syntax. I don't think I am using the right quotations when I am calling the function.

Here is how it looks when I inspect elements on the web browser.

在此处输入图片说明

You need to set the onload attribute on the <body> , not any other tag. Or you could add a snippet of javascript on the page to do the same thing:

window.onload = function() { name("rename", "editor"); });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM