简体   繁体   English

Onclick 功能在 IE 11 中不起作用

[英]Onclick function not work in IE 11

I'm trying to add a submit function in my HTML and refer to a js file with my function.我正在尝试在我的 HTML 中添加一个提交函数,并使用我的函数引用一个 js 文件。 The code runs successfully in Chrome but not in IE11.该代码在 Chrome 中成功运行,但在 IE11 中无法运行。 The error message is "submitFunc(event) is undefined".错误消息是“submitFunc(event) 未定义”。 Could anyone help me fix this problem?谁能帮我解决这个问题? I have tried everything I can.我已经尽我所能。 TT TT

 function submitFunc(event) { console.log("Hey what are you looking for? ") }
 <html> <div> <input class="btn btn-primary" type="submit" value="submit" onclick="submitFunc(event)"> </div> </html> <script type="text/javascript" src="/static/js/main.js"></script>

It might be that your <script> tag in outside of the <html>...</html> block.可能是您的<script>标记位于<html>...</html>块之外。 Try moving it up into the a <head>...</head> section just after the first <html> tag.尝试将它移到第一个<html>标记之后的<head>...</head>部分。

I don't know if you still need help, but you're loading the JavaScript file after setting up the on-click event.我不知道您是否还需要帮助,但是您正在设置点击事件后加载 JavaScript 文件。 I would assume that means you don't have the function defined yet.我认为这意味着您还没有定义函数。 I would move the "script" tag before the elements.我会在元素之前移动“脚本”标签。

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

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