简体   繁体   English

当我尝试在节点中运行函数时,为什么Onclick =“ function()”显示404?

[英]why does Onclick=“function()” shows up 404 when I am trying to run a function in node?

I am trying to run the function displayeditor, when I click the submit button. 单击提交按钮时,我正在尝试运行displayitor功能。 However on the webpage it shows 404 when the button is clicked. 但是,在网页上,单击按钮时会显示404。 Can't seem to figure out why it does that. 似乎无法弄清楚为什么这样做。 I am using node.js. 我正在使用node.js。 jade express. 玉快递。

extends layout

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

The button inside the form will submit the form by default on click, use e.preventDefault() or return false; 表单内的按钮默认会在单击时提交表单,使用e.preventDefault()return false; to prevent the behaviour. 以防止这种行为。

Try rewriting your Jade file as follows. 尝试如下重写您的Jade文件。 There were a few errors here: 这里有一些错误:

  • Your Javascript code needs to be actual Javascript -- you need parenthesis / etc. Jade will NOT substitute out your JS code itself -- just the HTML tags. 您的Javascript代码必须是实际的Javascript-您需要括号/等。Jade不会替代您的JS代码本身-只是HTML标记。
  • Your JS function needs to return false -- otherwise the button you click will trigger a form submission, which means your user will POST that data to your server (which I don't think you want). 您的JS函数需要返回false;否则,您单击的按钮将触发表单提交,这意味着您的用户会将这些数据发布到您的服务器(我认为您不想要)。

Here's the working code: 这是工作代码:

extends layout

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么onclick函数在onclick上运行,而在我手动调用时却不能运行? - Why does the onclick function run on onclick, but not when I call it manually? 为什么我把 this.onclick=' '; 放在 function 运行一次? - Why does the function run once when I put this.onclick=' ';? 为什么我的if函数不针对“timer”变量? 当计时器达到0时,我试图让它提醒/控制台“时间到了” - Why isn't my if function targeting the “timer” variable? I am trying to get it to alert/console “time is up” when the timer hits 0 我正在尝试使 onclick 功能在 tr 元素中工作 - I am trying to make onclick function work in a tr element 当我完成拖动并且鼠标上升时,如何使我的可拖动 div 不运行 onClick function? - How to make my draggable div not run the onClick function when I finish dragging and my mouse goes up? 为什么我的 useEffect react 函数在页面加载时运行,尽管我给了它第二个值数组 - Why does my useEffect react function run when the page loads although I am giving it a second value array 折射的onclick函数不会运行 - refractored onclick function does not run 如果多次运行初始化,为什么我的jquery onclick函数会打开和关闭? - Why does my jquery onclick function toggle on and off, if I run initialization more than once? 为什么我的 onclick 属性在提交时不运行 function? - Why does my onclick property not run the function upon submit? 当我尝试执行节点js应用程序时出现错误:findById不是函数 - there is an error when I am trying to execute a node js app: findById is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM