为什么不显示错误-javascript函数未闭合的花括号? [英] WHY don't show error - javascript functions unclosed curly brackets ?

查看:123
本文介绍了为什么不显示错误-javascript函数未闭合的花括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我错过了为html文件中的javascript函数提供大括号,请不要像HTML编译器一样在HTML验证器中显示错误?



什么我试过了:



为什么下面的代码在HTML验证器中没有显示错误[比如> https://html5.validator.nu]? [ ^ ]你可以看到我错误地错过了函数substitute()的封闭大括号。正如你所知,在C / CPP编程编译器会说错误,如果有任何函数程序员错过了结束花括号。

就像那个工具/ html验证器那里有关于我的示例代码缺少花括号的相同内容吗?



If i missed to give curly brackets for a javascript function in html file don't show error in HTML validator as like C compiler?

What I have tried:

Why below code does not show error in HTML validator [like https://html5.validator.nu]?[^] You can see i have mistakenly missed the enclosing curly bracket of function substitute().As you know in C/CPP programming compiler will say error if any function ending curly braces missed by a programmer.
Like that is any tool/ html validator there to tell about the same about missing curly braces for my example code?

<!DOCTYPE html>
<html> 
<head>
  <title>JavaScript Example</title> 
  <script type="text/javascript">
    function substitute() {
       var myValue = document.getElementById('myTextBox').value;
        
       if(myValue.length == 0) {
	  alert('Please enter a real value in the text box!');
          return;
       }
       var myTitle = document.getElementById('title');
       myTitle.innerHTML = myValue;
   </script>
</head>
<body>
  <h1 id="title">JavaScript Example</h1>

  <input type="text" id="myTextBox" />
  <input type="submit" value="click me" />
</body>
</html>

推荐答案

顾名思义,这是一个HTML验证器,只会查找HTML语法错误和不良做法。鉴于您正在寻找的是JavaScript验证器,请尝试 JSLint [ ^ ]。我在那里输入了你的JavaScript代码,

As the name suggests, that is an HTML validator and would only look for the HTML syntax errors and bad practices. Whereas, what you are looking for is JavaScript validator, try JSLint[^]. I entered your JavaScript code there,
function substitute() {
       var myValue = document.getElementById('myTextBox').value;
        
       if(myValue.length == 0) {
	  alert('Please enter a real value in the text box!');
          return;
       }
       var myTitle = document.getElementById('title');
       myTitle.innerHTML = myValue;



看看错误,页面底部已经有6个错误了,它还告诉我们JavaScript引擎期待a}但找到了结束


这篇关于为什么不显示错误-javascript函数未闭合的花括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆