简体   繁体   English

无法使用JavaScript eventlistener运行PHP

[英]Can't run PHP with JavaScript eventlistener

Im using PHP to create a canvas to write and it will output text as result to a textarea(done by other functions). 我使用PHP创建了一个画布来编写,它将结果文本输出到textarea(由其他功能完成)。 There are some other input tag too such as title etc to get input from users. 也有一些其他输入标签,例如标题等,可以从用户那里获取输入。 The value/content from these input tag (title and textarea) will submit to the database with form method "post". 这些输入标记(标题和文本区域)中的值/内容将以表单方法“ post”提交到数据库。 However i have some buttons with event listener function attached for the canvas part ("undo" or "redo" strokes). 但是我有一些带有事件侦听器功能的按钮(用于画布部分)(“撤消”或“重做”笔触)。 The saving part already successful been done but the event listener part seems to not working, each time i press undo or redo the window will load like my submit button and my canvas wont undo or redo the strokes and i'm not sure what is wrong with the code, anyone can help me? 保存部分已经成功完成,但是事件侦听器部分似乎不起作用,每次我按undo或Redo时,窗口将像我的提交按钮一样加载,而我的画布不会撤消或重做笔划,而且我不确定这是怎么回事有了代码,有人可以帮助我吗? The example of code is something as below: 代码示例如下所示:

<body>
<form method="something.php" method="post">
<label for = "datetime">Date Created:</label><br>
<input type="text" name="inputDate" size="20" disabled>   //disabled because i put timestamp
<input type= "submit" name = "submit" value="Save"></input>
<pre><textarea id="result" name = "res"></textarea></pre>    //the text will output here
</form>
<br><canvas id="myCanvas" width="400" height="400"></canvas><br>   //where my i draw
<button id="undo" class = "button" >Undo</button>
</body>

<script>
(function () 
{
var undo = document.getElementById('undo');
..
..
 undo.addEventListener('click', function () 
{
if (!inkRecog.isEmpty()) 
{
inkRecog.undo();    
}
doRecog();
},
 false);
 })();
</script>

my inkRecog.undo already declare in another form, previously working, but when i put the form method in the body it won't work. 我的inkRecog.undo已经以另一种形式声明了,以前可以正常工作,但是当我将form方法放在正文中时,它将无法工作。

// //

You need to 你需要

return false;

at the end of the event listener under doRecog(); 在事件侦听器的结尾处,在doRecog()下;

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

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