javascript 函数在node.js Jade Express 中不起作用

标签 javascript node.js function

这是我的代码:

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';
            }

当我在网络上运行它时,我的 javascript 函数没有被调用。我似乎无法弄清楚为什么,但我认为这与语法有关。我认为在调用该函数时我没有使用正确的引号。

这是我在网络浏览器上检查元素时的外观。

enter image description here

最佳答案

您需要设置onload <body> 上的属性,而不是任何其他标签。 或者您可以在页面上添加一段 javascript 来执行相同的操作:

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

关于javascript 函数在node.js Jade Express 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27558117/

相关文章:

javascript - 转换为 map 对象

javascript - AngularJs Controller 中的实时时钟功能

node.js - Express-子域看不到路由

node.js - 蒙戈访问量最大

r - 有没有办法找出函数的返回类型?

c - 函数调用的段错误

javascript - 从Excel中检索数据并显示在页面中

javascript - Node.js API 与 express 和 mysql - 获取记录计数、页码……并提供分页

javascript - 找到字符串中最长的单词?

javascript - jQuery获取div的值并显示到其他div