[英]How do these Javascript functions run?
I have two controls in my form (among others) that run Javascript functions on some event.我的表单中有两个控件(以及其他控件),它们在某个事件上运行 Javascript 函数。 One of them is a input of type text and I added three Javascript functions to the
onblur
event separated by a space like this:其中之一是文本类型的输入,我向
onblur
事件添加了三个 Javascript 函数,由这样的空格分隔:
<input type="text" onBlur="func1() func2() func3()"></input>
The second control is a combo and to this one I added two Javascript functions to the onchange
event separated by a semi-colon like this:第二个控件是一个组合,为此我向
onchange
事件添加了两个 Javascript 函数,用分号分隔,如下所示:
<select "onchange="func1(); func2()">...</select>
My problem is that both of them work.我的问题是它们都有效。 As I know, the correct syntax is the one with semi-colons.
据我所知,正确的语法是带有分号的语法。 Why does the one with spaces work ?
为什么有空格的那个有效?
Which browser are you testing this in?你在哪个浏览器中测试这个? It's likely that the browser is trying to "do the right thing" for you.
浏览器很可能正在尝试为您“做正确的事情”。 Many browsers, IE in particular, will take a guess at what the developer's intention was when encountering non-standards compliant code.
许多浏览器,尤其是 IE,会在遇到不符合标准的代码时猜测开发人员的意图。
Semicolons in JavaScript are optional. JavaScript 中的分号是可选的。 This is a good blog post to explain: https://mislav.net/2010/05/semicolons/
这是一篇很好的博文来解释: https : //mislav.net/2010/05/semicolons/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.