Error analysis for property '×' value is null, undefined, or not a Function object

Why sometimes the js method we write exists and is correct, the browser F12 console still has errors:

The value of property 'x' is null, undefined, or not a Function object?

If the development experience is rich, then this problem is not difficult to solve, otherwise it will give people the feeling of collapse!

If you want to thoroughly analyze the cause of this error, then by the way, the loading order of html

Needless to say, the order is of course loaded from top to bottom, followed by head element -> body element; if it is jsp, it will be sent directly to the server.

one:

1. The external file code referenced in the head element is downloaded at the beginning.

2. When encountering a script, the browser suspends parsing (non-suspended download), and transfers control to the JavaScript engine (interpreter). If the <script> element references an external script, download the script, otherwise execute it directly. Hand over to the browser rendering engine

two:

1. When the browser parses the code in the body, it will parse according to a part of the style declared in the head (if the external file referenced in the head is not downloaded, it will continue to download)

2. If there is a <script> element in the body, the control will also be handed over to the JavaScript engine to interpret and execute

3. When the code in the body is all executed and the CSS style of the entire page is loaded, the CSS will re-render the HTML elements of the entire page.

Note: It is better to write <script> to the back of the body tag,

Reason: JavaScript will manipulate html elements. If JavaScript is written before the body is loaded, it will cause the error that JavaScript cannot find the page element.

Usually js is written in the <script> element of the <head> element, and js code is rarely written in the body, usually only

window.onload: It will be executed after all the content in the page is loaded (including large files such as pictures and music)

$(document).ready(): Executed immediately after all DOM trees in the page are drawn

Back to the topic of the article:

浏览器解释执行<script>元素中的代码时若遇到语法错误,那么这一整个<script>元素中的代码也都将会解释失败!(包括里面所有的js方法/函数)

以下是我遇到的情形:查询按钮绑定的方法没有错误,不要问我为啥确定没有错误,因为我压根就没改过。。

Tips:

1.遇到这种错误时最好通过Ctrl+F5强制刷新(好处在于浏览器不会使用缓存,直接当新的DOM文档来解释执行!),此时错误信息会原形毕露:

进入该错误:

源文件:

最后在java代码块<%=submitFlag%>外加了双引号“”才得以解决!

有个异常要抛出来:submitFlag也是字符串类型,为什么会不识别呢?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325520599&siteId=291194637