这是我的代码:
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 函数没有被调用。我似乎无法弄清楚为什么,但我认为这与语法有关。我认为在调用该函数时我没有使用正确的引号。
这是我在网络浏览器上检查元素时的外观。
最佳答案
您需要设置onload
<body>
上的属性,而不是任何其他标签。 或者您可以在页面上添加一段 javascript 来执行相同的操作:
window.onload = function() { name("rename", "editor"); });
关于javascript 函数在node.js Jade Express 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27558117/